diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/utils/src/plugin/index.js b/packages/utils/src/plugin/index.js deleted file mode 100644 index abc456d..0000000 --- a/packages/utils/src/plugin/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as pluginTarget } from './pluginTarget'; -import * as mixins from './mixins'; -export { mixins }; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/utils/src/plugin/index.js b/packages/utils/src/plugin/index.js deleted file mode 100644 index abc456d..0000000 --- a/packages/utils/src/plugin/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as pluginTarget } from './pluginTarget'; -import * as mixins from './mixins'; -export { mixins }; diff --git a/packages/utils/src/plugin/mixins.js b/packages/utils/src/plugin/mixins.js deleted file mode 100644 index 114de2a..0000000 --- a/packages/utils/src/plugin/mixins.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Mixes all enumerable properties and methods from a source object to a target object. - * - * @memberof PIXI.utils.mixins - * @function mixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function mixin(target, source) -{ - if (!target || !source) return; - // in ES8/ES2017, this would be really easy: - // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - - // get all the enumerable property keys - const keys = Object.keys(source); - - // loop through properties - for (let i = 0; i < keys.length; ++i) - { - const propertyName = keys[i]; - - // Set the property using the property descriptor - this works for accessors and normal value properties - Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); - } -} - -const mixins = []; - -/** - * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation - * can take effect. - * - * @memberof PIXI.utils.mixins - * @function delayMixin - * @private - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function delayMixin(target, source) -{ - mixins.push(target, source); -} - -/** - * Handles all mixins queued via delayMixin(). - * - * @memberof PIXI.utils.mixins - * @function performMixins - * @private - */ -export function performMixins() -{ - for (let i = 0; i < mixins.length; i += 2) - { - mixin(mixins[i], mixins[i + 1]); - } - mixins.length = 0; -} diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/utils/src/plugin/index.js b/packages/utils/src/plugin/index.js deleted file mode 100644 index abc456d..0000000 --- a/packages/utils/src/plugin/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as pluginTarget } from './pluginTarget'; -import * as mixins from './mixins'; -export { mixins }; diff --git a/packages/utils/src/plugin/mixins.js b/packages/utils/src/plugin/mixins.js deleted file mode 100644 index 114de2a..0000000 --- a/packages/utils/src/plugin/mixins.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Mixes all enumerable properties and methods from a source object to a target object. - * - * @memberof PIXI.utils.mixins - * @function mixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function mixin(target, source) -{ - if (!target || !source) return; - // in ES8/ES2017, this would be really easy: - // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - - // get all the enumerable property keys - const keys = Object.keys(source); - - // loop through properties - for (let i = 0; i < keys.length; ++i) - { - const propertyName = keys[i]; - - // Set the property using the property descriptor - this works for accessors and normal value properties - Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); - } -} - -const mixins = []; - -/** - * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation - * can take effect. - * - * @memberof PIXI.utils.mixins - * @function delayMixin - * @private - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function delayMixin(target, source) -{ - mixins.push(target, source); -} - -/** - * Handles all mixins queued via delayMixin(). - * - * @memberof PIXI.utils.mixins - * @function performMixins - * @private - */ -export function performMixins() -{ - for (let i = 0; i < mixins.length; i += 2) - { - mixin(mixins[i], mixins[i + 1]); - } - mixins.length = 0; -} diff --git a/packages/utils/src/plugin/pluginTarget.js b/packages/utils/src/plugin/pluginTarget.js deleted file mode 100644 index c4f7a67..0000000 --- a/packages/utils/src/plugin/pluginTarget.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Mixins functionality to make an object have "plugins". - * - * @example - * function MyObject() {} - * - * pluginTarget.mixin(MyObject); - * - * @function pluginTarget - * @memberof PIXI.utils - * @type {mixin} - * @param {object} obj - The object to mix into. - */ -function pluginTarget(obj) -{ - obj.__plugins = {}; - - /** - * Adds a plugin to an object - * - * @param {string} pluginName - The events that should be listed. - * @param {Function} ctor - The constructor function for the plugin. - */ - obj.registerPlugin = function registerPlugin(pluginName, ctor) - { - obj.__plugins[pluginName] = ctor; - }; - - /** - * Instantiates all the plugins of this object - * - */ - obj.prototype.initPlugins = function initPlugins() - { - this.plugins = this.plugins || {}; - - for (const o in obj.__plugins) - { - this.plugins[o] = new (obj.__plugins[o])(this); - } - }; - - /** - * Removes all the plugins of this object - * - */ - obj.prototype.destroyPlugins = function destroyPlugins() - { - for (const o in this.plugins) - { - this.plugins[o].destroy(); - this.plugins[o] = null; - } - - this.plugins = null; - }; -} - -export default { - /** - * Mixes in the properties of the pluginTarget into another object - * - * @param {object} obj - The obj to mix into - */ - mixin: function mixin(obj) - { - pluginTarget(obj); - }, -}; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/utils/src/plugin/index.js b/packages/utils/src/plugin/index.js deleted file mode 100644 index abc456d..0000000 --- a/packages/utils/src/plugin/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as pluginTarget } from './pluginTarget'; -import * as mixins from './mixins'; -export { mixins }; diff --git a/packages/utils/src/plugin/mixins.js b/packages/utils/src/plugin/mixins.js deleted file mode 100644 index 114de2a..0000000 --- a/packages/utils/src/plugin/mixins.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Mixes all enumerable properties and methods from a source object to a target object. - * - * @memberof PIXI.utils.mixins - * @function mixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function mixin(target, source) -{ - if (!target || !source) return; - // in ES8/ES2017, this would be really easy: - // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - - // get all the enumerable property keys - const keys = Object.keys(source); - - // loop through properties - for (let i = 0; i < keys.length; ++i) - { - const propertyName = keys[i]; - - // Set the property using the property descriptor - this works for accessors and normal value properties - Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); - } -} - -const mixins = []; - -/** - * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation - * can take effect. - * - * @memberof PIXI.utils.mixins - * @function delayMixin - * @private - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function delayMixin(target, source) -{ - mixins.push(target, source); -} - -/** - * Handles all mixins queued via delayMixin(). - * - * @memberof PIXI.utils.mixins - * @function performMixins - * @private - */ -export function performMixins() -{ - for (let i = 0; i < mixins.length; i += 2) - { - mixin(mixins[i], mixins[i + 1]); - } - mixins.length = 0; -} diff --git a/packages/utils/src/plugin/pluginTarget.js b/packages/utils/src/plugin/pluginTarget.js deleted file mode 100644 index c4f7a67..0000000 --- a/packages/utils/src/plugin/pluginTarget.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Mixins functionality to make an object have "plugins". - * - * @example - * function MyObject() {} - * - * pluginTarget.mixin(MyObject); - * - * @function pluginTarget - * @memberof PIXI.utils - * @type {mixin} - * @param {object} obj - The object to mix into. - */ -function pluginTarget(obj) -{ - obj.__plugins = {}; - - /** - * Adds a plugin to an object - * - * @param {string} pluginName - The events that should be listed. - * @param {Function} ctor - The constructor function for the plugin. - */ - obj.registerPlugin = function registerPlugin(pluginName, ctor) - { - obj.__plugins[pluginName] = ctor; - }; - - /** - * Instantiates all the plugins of this object - * - */ - obj.prototype.initPlugins = function initPlugins() - { - this.plugins = this.plugins || {}; - - for (const o in obj.__plugins) - { - this.plugins[o] = new (obj.__plugins[o])(this); - } - }; - - /** - * Removes all the plugins of this object - * - */ - obj.prototype.destroyPlugins = function destroyPlugins() - { - for (const o in this.plugins) - { - this.plugins[o].destroy(); - this.plugins[o] = null; - } - - this.plugins = null; - }; -} - -export default { - /** - * Mixes in the properties of the pluginTarget into another object - * - * @param {object} obj - The obj to mix into - */ - mixin: function mixin(obj) - { - pluginTarget(obj); - }, -}; diff --git a/packages/utils/test/index.js b/packages/utils/test/index.js index 52f00ce..bf8041e 100755 --- a/packages/utils/test/index.js +++ b/packages/utils/test/index.js @@ -99,140 +99,6 @@ }); }); - describe('getUrlFileExtension', function () - { - it('should exist', function () - { - expect(utils.getUrlFileExtension) - .to.be.a('function'); - }); - - it('should return extension of URL in lower case', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when absolute', function () - { - const imageType = utils.getUrlFileExtension('/you/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when relative', function () - { - const imageType = utils.getUrlFileExtension('me/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when just an extension', function () - { - const imageType = utils.getUrlFileExtension('.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp/this/is/a/path/me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#not-today'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#path/s/not-today.svg'); - - expect(imageType) - .to.equal('png'); - }); - }); - - describe('getSvgSize', function () - { - it('should exist', function () - { - expect(utils.getSvgSize) - .to.be.a('function'); - }); - - it('should return a size object with width and height from an SVG string', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return a size object from an SVG string with inverted quotes', function () - { - const svgSize = utils.getSvgSize(""); // eslint-disable-line quotes - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should work with px values', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return an empty object when width and/or height is missing', function () - { - const svgSize = utils.getSvgSize(''); - - expect(Object.keys(svgSize).length) - .to.equal(0); - }); - }); - describe('sayHello', function () { it('should exist', function () diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/utils/src/plugin/index.js b/packages/utils/src/plugin/index.js deleted file mode 100644 index abc456d..0000000 --- a/packages/utils/src/plugin/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as pluginTarget } from './pluginTarget'; -import * as mixins from './mixins'; -export { mixins }; diff --git a/packages/utils/src/plugin/mixins.js b/packages/utils/src/plugin/mixins.js deleted file mode 100644 index 114de2a..0000000 --- a/packages/utils/src/plugin/mixins.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Mixes all enumerable properties and methods from a source object to a target object. - * - * @memberof PIXI.utils.mixins - * @function mixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function mixin(target, source) -{ - if (!target || !source) return; - // in ES8/ES2017, this would be really easy: - // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - - // get all the enumerable property keys - const keys = Object.keys(source); - - // loop through properties - for (let i = 0; i < keys.length; ++i) - { - const propertyName = keys[i]; - - // Set the property using the property descriptor - this works for accessors and normal value properties - Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); - } -} - -const mixins = []; - -/** - * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation - * can take effect. - * - * @memberof PIXI.utils.mixins - * @function delayMixin - * @private - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function delayMixin(target, source) -{ - mixins.push(target, source); -} - -/** - * Handles all mixins queued via delayMixin(). - * - * @memberof PIXI.utils.mixins - * @function performMixins - * @private - */ -export function performMixins() -{ - for (let i = 0; i < mixins.length; i += 2) - { - mixin(mixins[i], mixins[i + 1]); - } - mixins.length = 0; -} diff --git a/packages/utils/src/plugin/pluginTarget.js b/packages/utils/src/plugin/pluginTarget.js deleted file mode 100644 index c4f7a67..0000000 --- a/packages/utils/src/plugin/pluginTarget.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Mixins functionality to make an object have "plugins". - * - * @example - * function MyObject() {} - * - * pluginTarget.mixin(MyObject); - * - * @function pluginTarget - * @memberof PIXI.utils - * @type {mixin} - * @param {object} obj - The object to mix into. - */ -function pluginTarget(obj) -{ - obj.__plugins = {}; - - /** - * Adds a plugin to an object - * - * @param {string} pluginName - The events that should be listed. - * @param {Function} ctor - The constructor function for the plugin. - */ - obj.registerPlugin = function registerPlugin(pluginName, ctor) - { - obj.__plugins[pluginName] = ctor; - }; - - /** - * Instantiates all the plugins of this object - * - */ - obj.prototype.initPlugins = function initPlugins() - { - this.plugins = this.plugins || {}; - - for (const o in obj.__plugins) - { - this.plugins[o] = new (obj.__plugins[o])(this); - } - }; - - /** - * Removes all the plugins of this object - * - */ - obj.prototype.destroyPlugins = function destroyPlugins() - { - for (const o in this.plugins) - { - this.plugins[o].destroy(); - this.plugins[o] = null; - } - - this.plugins = null; - }; -} - -export default { - /** - * Mixes in the properties of the pluginTarget into another object - * - * @param {object} obj - The obj to mix into - */ - mixin: function mixin(obj) - { - pluginTarget(obj); - }, -}; diff --git a/packages/utils/test/index.js b/packages/utils/test/index.js index 52f00ce..bf8041e 100755 --- a/packages/utils/test/index.js +++ b/packages/utils/test/index.js @@ -99,140 +99,6 @@ }); }); - describe('getUrlFileExtension', function () - { - it('should exist', function () - { - expect(utils.getUrlFileExtension) - .to.be.a('function'); - }); - - it('should return extension of URL in lower case', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when absolute', function () - { - const imageType = utils.getUrlFileExtension('/you/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when relative', function () - { - const imageType = utils.getUrlFileExtension('me/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when just an extension', function () - { - const imageType = utils.getUrlFileExtension('.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp/this/is/a/path/me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#not-today'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#path/s/not-today.svg'); - - expect(imageType) - .to.equal('png'); - }); - }); - - describe('getSvgSize', function () - { - it('should exist', function () - { - expect(utils.getSvgSize) - .to.be.a('function'); - }); - - it('should return a size object with width and height from an SVG string', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return a size object from an SVG string with inverted quotes', function () - { - const svgSize = utils.getSvgSize(""); // eslint-disable-line quotes - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should work with px values', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return an empty object when width and/or height is missing', function () - { - const svgSize = utils.getSvgSize(''); - - expect(Object.keys(svgSize).length) - .to.equal(0); - }); - }); - describe('sayHello', function () { it('should exist', function () diff --git a/tools/builder/index.js b/tools/builder/index.js deleted file mode 100644 index 49114e0..0000000 --- a/tools/builder/index.js +++ /dev/null @@ -1,115 +0,0 @@ -const path = require('path'); -const buble = require('rollup-plugin-buble'); -const resolve = require('rollup-plugin-node-resolve'); -const string = require('rollup-plugin-string'); -const uglify = require('rollup-plugin-uglify'); -const { minify } = require('uglify-es'); -const minimist = require('minimist'); -const commonjs = require('rollup-plugin-commonjs'); -const builtins = require('rollup-plugin-node-builtins'); -const replace = require('rollup-plugin-replace'); -const preprocess = require('rollup-plugin-preprocess').default; - -const pkg = require(path.resolve('./package')); -const safeName = path.basename(pkg.name); -const input = 'src/index.js'; - -const { prod, format, output } = minimist(process.argv.slice(2), { - string: ['format', 'output'], - boolean: ['prod'], - default: { - format: 'es', - prod: false, - output: '', - }, - alias: { - f: 'format', - p: 'prod', - o: 'output', - }, -}); - -// Allow overriding output, but default to "module" and "main" fields -const file = output || (format === 'es' ? pkg.module : pkg.main); - -const plugins = [ - resolve({ - browser: true, - preferBuiltins: true, - }), - builtins(), - commonjs({ - namedExports: { - 'resource-loader': ['Resource'], - 'pixi-gl-core': ['GLFramebuffer'], - }, - }), - string({ - include: [ - 'src/**/*.frag', - 'src/**/*.vert', - ], - }), - replace({ - __VERSION__: pkg.version, - }), - preprocess({ - context: { - DEV: !prod, - DEVELOPMENT: !prod, - PROD: prod, - PRODUCTION: prod, - }, - }), - buble(), -]; - -if (prod) -{ - let first = true; - - plugins.push(uglify({ - mangle: true, - compress: true, - output: { - comments(node, comment) - { - const { value, type } = comment; - - if (type === 'comment2' && first) - { - first = false; - - return value[0] === '!'; - } - - return false; - }, - }, - }, minify)); -} - -const compiled = (new Date()).toUTCString().replace(/GMT/g, 'UTC'); - -const banner = `/*! - * ${pkg.name} - v${pkg.version} - * Compiled ${compiled} - * - * pixi-filters is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license - */\n`; - -const name = `__${safeName.replace(/-/g, '_')}`; - -module.exports = { - banner, - name, - input, - output: { - file, - format, - }, - external: Object.keys(pkg.dependencies || []), - sourcemap: true, - plugins, -}; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/utils/src/plugin/index.js b/packages/utils/src/plugin/index.js deleted file mode 100644 index abc456d..0000000 --- a/packages/utils/src/plugin/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as pluginTarget } from './pluginTarget'; -import * as mixins from './mixins'; -export { mixins }; diff --git a/packages/utils/src/plugin/mixins.js b/packages/utils/src/plugin/mixins.js deleted file mode 100644 index 114de2a..0000000 --- a/packages/utils/src/plugin/mixins.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Mixes all enumerable properties and methods from a source object to a target object. - * - * @memberof PIXI.utils.mixins - * @function mixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function mixin(target, source) -{ - if (!target || !source) return; - // in ES8/ES2017, this would be really easy: - // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - - // get all the enumerable property keys - const keys = Object.keys(source); - - // loop through properties - for (let i = 0; i < keys.length; ++i) - { - const propertyName = keys[i]; - - // Set the property using the property descriptor - this works for accessors and normal value properties - Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); - } -} - -const mixins = []; - -/** - * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation - * can take effect. - * - * @memberof PIXI.utils.mixins - * @function delayMixin - * @private - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function delayMixin(target, source) -{ - mixins.push(target, source); -} - -/** - * Handles all mixins queued via delayMixin(). - * - * @memberof PIXI.utils.mixins - * @function performMixins - * @private - */ -export function performMixins() -{ - for (let i = 0; i < mixins.length; i += 2) - { - mixin(mixins[i], mixins[i + 1]); - } - mixins.length = 0; -} diff --git a/packages/utils/src/plugin/pluginTarget.js b/packages/utils/src/plugin/pluginTarget.js deleted file mode 100644 index c4f7a67..0000000 --- a/packages/utils/src/plugin/pluginTarget.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Mixins functionality to make an object have "plugins". - * - * @example - * function MyObject() {} - * - * pluginTarget.mixin(MyObject); - * - * @function pluginTarget - * @memberof PIXI.utils - * @type {mixin} - * @param {object} obj - The object to mix into. - */ -function pluginTarget(obj) -{ - obj.__plugins = {}; - - /** - * Adds a plugin to an object - * - * @param {string} pluginName - The events that should be listed. - * @param {Function} ctor - The constructor function for the plugin. - */ - obj.registerPlugin = function registerPlugin(pluginName, ctor) - { - obj.__plugins[pluginName] = ctor; - }; - - /** - * Instantiates all the plugins of this object - * - */ - obj.prototype.initPlugins = function initPlugins() - { - this.plugins = this.plugins || {}; - - for (const o in obj.__plugins) - { - this.plugins[o] = new (obj.__plugins[o])(this); - } - }; - - /** - * Removes all the plugins of this object - * - */ - obj.prototype.destroyPlugins = function destroyPlugins() - { - for (const o in this.plugins) - { - this.plugins[o].destroy(); - this.plugins[o] = null; - } - - this.plugins = null; - }; -} - -export default { - /** - * Mixes in the properties of the pluginTarget into another object - * - * @param {object} obj - The obj to mix into - */ - mixin: function mixin(obj) - { - pluginTarget(obj); - }, -}; diff --git a/packages/utils/test/index.js b/packages/utils/test/index.js index 52f00ce..bf8041e 100755 --- a/packages/utils/test/index.js +++ b/packages/utils/test/index.js @@ -99,140 +99,6 @@ }); }); - describe('getUrlFileExtension', function () - { - it('should exist', function () - { - expect(utils.getUrlFileExtension) - .to.be.a('function'); - }); - - it('should return extension of URL in lower case', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when absolute', function () - { - const imageType = utils.getUrlFileExtension('/you/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when relative', function () - { - const imageType = utils.getUrlFileExtension('me/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when just an extension', function () - { - const imageType = utils.getUrlFileExtension('.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp/this/is/a/path/me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#not-today'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#path/s/not-today.svg'); - - expect(imageType) - .to.equal('png'); - }); - }); - - describe('getSvgSize', function () - { - it('should exist', function () - { - expect(utils.getSvgSize) - .to.be.a('function'); - }); - - it('should return a size object with width and height from an SVG string', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return a size object from an SVG string with inverted quotes', function () - { - const svgSize = utils.getSvgSize(""); // eslint-disable-line quotes - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should work with px values', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return an empty object when width and/or height is missing', function () - { - const svgSize = utils.getSvgSize(''); - - expect(Object.keys(svgSize).length) - .to.equal(0); - }); - }); - describe('sayHello', function () { it('should exist', function () diff --git a/tools/builder/index.js b/tools/builder/index.js deleted file mode 100644 index 49114e0..0000000 --- a/tools/builder/index.js +++ /dev/null @@ -1,115 +0,0 @@ -const path = require('path'); -const buble = require('rollup-plugin-buble'); -const resolve = require('rollup-plugin-node-resolve'); -const string = require('rollup-plugin-string'); -const uglify = require('rollup-plugin-uglify'); -const { minify } = require('uglify-es'); -const minimist = require('minimist'); -const commonjs = require('rollup-plugin-commonjs'); -const builtins = require('rollup-plugin-node-builtins'); -const replace = require('rollup-plugin-replace'); -const preprocess = require('rollup-plugin-preprocess').default; - -const pkg = require(path.resolve('./package')); -const safeName = path.basename(pkg.name); -const input = 'src/index.js'; - -const { prod, format, output } = minimist(process.argv.slice(2), { - string: ['format', 'output'], - boolean: ['prod'], - default: { - format: 'es', - prod: false, - output: '', - }, - alias: { - f: 'format', - p: 'prod', - o: 'output', - }, -}); - -// Allow overriding output, but default to "module" and "main" fields -const file = output || (format === 'es' ? pkg.module : pkg.main); - -const plugins = [ - resolve({ - browser: true, - preferBuiltins: true, - }), - builtins(), - commonjs({ - namedExports: { - 'resource-loader': ['Resource'], - 'pixi-gl-core': ['GLFramebuffer'], - }, - }), - string({ - include: [ - 'src/**/*.frag', - 'src/**/*.vert', - ], - }), - replace({ - __VERSION__: pkg.version, - }), - preprocess({ - context: { - DEV: !prod, - DEVELOPMENT: !prod, - PROD: prod, - PRODUCTION: prod, - }, - }), - buble(), -]; - -if (prod) -{ - let first = true; - - plugins.push(uglify({ - mangle: true, - compress: true, - output: { - comments(node, comment) - { - const { value, type } = comment; - - if (type === 'comment2' && first) - { - first = false; - - return value[0] === '!'; - } - - return false; - }, - }, - }, minify)); -} - -const compiled = (new Date()).toUTCString().replace(/GMT/g, 'UTC'); - -const banner = `/*! - * ${pkg.name} - v${pkg.version} - * Compiled ${compiled} - * - * pixi-filters is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license - */\n`; - -const name = `__${safeName.replace(/-/g, '_')}`; - -module.exports = { - banner, - name, - input, - output: { - file, - format, - }, - external: Object.keys(pkg.dependencies || []), - sourcemap: true, - plugins, -}; diff --git a/tools/builder/package.json b/tools/builder/package.json index 216f941..f9d1aa9 100644 --- a/tools/builder/package.json +++ b/tools/builder/package.json @@ -2,8 +2,12 @@ "name": "@internal/builder", "version": "5.0.0-alpha", "private": true, - "module": "index.js", - "devDependencies": { + "bin": { + "config": "./rollup.config.js" + }, + "dependencies": { + "buble": "^0.17.0", + "magic-string": "^0.22.4", "minimist": "^1.2.0", "rollup-plugin-buble": "^0.15.0", "rollup-plugin-commonjs": "^8.2.4", @@ -11,6 +15,7 @@ "rollup-plugin-node-resolve": "^3.0.0", "rollup-plugin-preprocess": "0.0.4", "rollup-plugin-replace": "^2.0.0", + "rollup-plugin-sourcemaps": "^0.4.2", "rollup-plugin-string": "^2.0.2", "rollup-plugin-uglify": "^2.0.1", "uglify-es": "^3.0.25" diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/utils/src/plugin/index.js b/packages/utils/src/plugin/index.js deleted file mode 100644 index abc456d..0000000 --- a/packages/utils/src/plugin/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as pluginTarget } from './pluginTarget'; -import * as mixins from './mixins'; -export { mixins }; diff --git a/packages/utils/src/plugin/mixins.js b/packages/utils/src/plugin/mixins.js deleted file mode 100644 index 114de2a..0000000 --- a/packages/utils/src/plugin/mixins.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Mixes all enumerable properties and methods from a source object to a target object. - * - * @memberof PIXI.utils.mixins - * @function mixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function mixin(target, source) -{ - if (!target || !source) return; - // in ES8/ES2017, this would be really easy: - // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - - // get all the enumerable property keys - const keys = Object.keys(source); - - // loop through properties - for (let i = 0; i < keys.length; ++i) - { - const propertyName = keys[i]; - - // Set the property using the property descriptor - this works for accessors and normal value properties - Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); - } -} - -const mixins = []; - -/** - * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation - * can take effect. - * - * @memberof PIXI.utils.mixins - * @function delayMixin - * @private - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function delayMixin(target, source) -{ - mixins.push(target, source); -} - -/** - * Handles all mixins queued via delayMixin(). - * - * @memberof PIXI.utils.mixins - * @function performMixins - * @private - */ -export function performMixins() -{ - for (let i = 0; i < mixins.length; i += 2) - { - mixin(mixins[i], mixins[i + 1]); - } - mixins.length = 0; -} diff --git a/packages/utils/src/plugin/pluginTarget.js b/packages/utils/src/plugin/pluginTarget.js deleted file mode 100644 index c4f7a67..0000000 --- a/packages/utils/src/plugin/pluginTarget.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Mixins functionality to make an object have "plugins". - * - * @example - * function MyObject() {} - * - * pluginTarget.mixin(MyObject); - * - * @function pluginTarget - * @memberof PIXI.utils - * @type {mixin} - * @param {object} obj - The object to mix into. - */ -function pluginTarget(obj) -{ - obj.__plugins = {}; - - /** - * Adds a plugin to an object - * - * @param {string} pluginName - The events that should be listed. - * @param {Function} ctor - The constructor function for the plugin. - */ - obj.registerPlugin = function registerPlugin(pluginName, ctor) - { - obj.__plugins[pluginName] = ctor; - }; - - /** - * Instantiates all the plugins of this object - * - */ - obj.prototype.initPlugins = function initPlugins() - { - this.plugins = this.plugins || {}; - - for (const o in obj.__plugins) - { - this.plugins[o] = new (obj.__plugins[o])(this); - } - }; - - /** - * Removes all the plugins of this object - * - */ - obj.prototype.destroyPlugins = function destroyPlugins() - { - for (const o in this.plugins) - { - this.plugins[o].destroy(); - this.plugins[o] = null; - } - - this.plugins = null; - }; -} - -export default { - /** - * Mixes in the properties of the pluginTarget into another object - * - * @param {object} obj - The obj to mix into - */ - mixin: function mixin(obj) - { - pluginTarget(obj); - }, -}; diff --git a/packages/utils/test/index.js b/packages/utils/test/index.js index 52f00ce..bf8041e 100755 --- a/packages/utils/test/index.js +++ b/packages/utils/test/index.js @@ -99,140 +99,6 @@ }); }); - describe('getUrlFileExtension', function () - { - it('should exist', function () - { - expect(utils.getUrlFileExtension) - .to.be.a('function'); - }); - - it('should return extension of URL in lower case', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when absolute', function () - { - const imageType = utils.getUrlFileExtension('/you/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when relative', function () - { - const imageType = utils.getUrlFileExtension('me/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when just an extension', function () - { - const imageType = utils.getUrlFileExtension('.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp/this/is/a/path/me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#not-today'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#path/s/not-today.svg'); - - expect(imageType) - .to.equal('png'); - }); - }); - - describe('getSvgSize', function () - { - it('should exist', function () - { - expect(utils.getSvgSize) - .to.be.a('function'); - }); - - it('should return a size object with width and height from an SVG string', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return a size object from an SVG string with inverted quotes', function () - { - const svgSize = utils.getSvgSize(""); // eslint-disable-line quotes - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should work with px values', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return an empty object when width and/or height is missing', function () - { - const svgSize = utils.getSvgSize(''); - - expect(Object.keys(svgSize).length) - .to.equal(0); - }); - }); - describe('sayHello', function () { it('should exist', function () diff --git a/tools/builder/index.js b/tools/builder/index.js deleted file mode 100644 index 49114e0..0000000 --- a/tools/builder/index.js +++ /dev/null @@ -1,115 +0,0 @@ -const path = require('path'); -const buble = require('rollup-plugin-buble'); -const resolve = require('rollup-plugin-node-resolve'); -const string = require('rollup-plugin-string'); -const uglify = require('rollup-plugin-uglify'); -const { minify } = require('uglify-es'); -const minimist = require('minimist'); -const commonjs = require('rollup-plugin-commonjs'); -const builtins = require('rollup-plugin-node-builtins'); -const replace = require('rollup-plugin-replace'); -const preprocess = require('rollup-plugin-preprocess').default; - -const pkg = require(path.resolve('./package')); -const safeName = path.basename(pkg.name); -const input = 'src/index.js'; - -const { prod, format, output } = minimist(process.argv.slice(2), { - string: ['format', 'output'], - boolean: ['prod'], - default: { - format: 'es', - prod: false, - output: '', - }, - alias: { - f: 'format', - p: 'prod', - o: 'output', - }, -}); - -// Allow overriding output, but default to "module" and "main" fields -const file = output || (format === 'es' ? pkg.module : pkg.main); - -const plugins = [ - resolve({ - browser: true, - preferBuiltins: true, - }), - builtins(), - commonjs({ - namedExports: { - 'resource-loader': ['Resource'], - 'pixi-gl-core': ['GLFramebuffer'], - }, - }), - string({ - include: [ - 'src/**/*.frag', - 'src/**/*.vert', - ], - }), - replace({ - __VERSION__: pkg.version, - }), - preprocess({ - context: { - DEV: !prod, - DEVELOPMENT: !prod, - PROD: prod, - PRODUCTION: prod, - }, - }), - buble(), -]; - -if (prod) -{ - let first = true; - - plugins.push(uglify({ - mangle: true, - compress: true, - output: { - comments(node, comment) - { - const { value, type } = comment; - - if (type === 'comment2' && first) - { - first = false; - - return value[0] === '!'; - } - - return false; - }, - }, - }, minify)); -} - -const compiled = (new Date()).toUTCString().replace(/GMT/g, 'UTC'); - -const banner = `/*! - * ${pkg.name} - v${pkg.version} - * Compiled ${compiled} - * - * pixi-filters is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license - */\n`; - -const name = `__${safeName.replace(/-/g, '_')}`; - -module.exports = { - banner, - name, - input, - output: { - file, - format, - }, - external: Object.keys(pkg.dependencies || []), - sourcemap: true, - plugins, -}; diff --git a/tools/builder/package.json b/tools/builder/package.json index 216f941..f9d1aa9 100644 --- a/tools/builder/package.json +++ b/tools/builder/package.json @@ -2,8 +2,12 @@ "name": "@internal/builder", "version": "5.0.0-alpha", "private": true, - "module": "index.js", - "devDependencies": { + "bin": { + "config": "./rollup.config.js" + }, + "dependencies": { + "buble": "^0.17.0", + "magic-string": "^0.22.4", "minimist": "^1.2.0", "rollup-plugin-buble": "^0.15.0", "rollup-plugin-commonjs": "^8.2.4", @@ -11,6 +15,7 @@ "rollup-plugin-node-resolve": "^3.0.0", "rollup-plugin-preprocess": "0.0.4", "rollup-plugin-replace": "^2.0.0", + "rollup-plugin-sourcemaps": "^0.4.2", "rollup-plugin-string": "^2.0.2", "rollup-plugin-uglify": "^2.0.1", "uglify-es": "^3.0.25" diff --git a/tools/builder/rollup.config.js b/tools/builder/rollup.config.js new file mode 100644 index 0000000..d22c49a --- /dev/null +++ b/tools/builder/rollup.config.js @@ -0,0 +1,130 @@ +import path from 'path'; +import fs from 'fs'; +import buble from 'buble'; +import thaw from './thaw'; +import transpile from 'rollup-plugin-buble'; +import resolve from 'rollup-plugin-node-resolve'; +import string from 'rollup-plugin-string'; +import sourcemaps from 'rollup-plugin-sourcemaps'; +import uglify from 'rollup-plugin-uglify'; +import { minify } from 'uglify-es'; +import minimist from 'minimist'; +import commonjs from 'rollup-plugin-commonjs'; +import builtins from 'rollup-plugin-node-builtins'; +import replace from 'rollup-plugin-replace'; +import preprocess from 'rollup-plugin-preprocess'; + +const pkg = require(path.resolve('./package')); +const input = 'src/index.js'; + +const { prod, bundle, deprecated } = minimist(process.argv.slice(2), { + string: ['deprecated'], + boolean: ['prod', 'bundle'], + default: { + prod: false, + bundle: false, + }, + alias: { + p: 'prod', + b: 'bundle', + r: 'deprecated', + }, +}); + +const plugins = [ + sourcemaps(), + resolve({ + browser: true, + preferBuiltins: true, + }), + builtins(), + commonjs({ + namedExports: { + 'resource-loader': ['Resource'], + 'pixi-gl-core': ['GLFramebuffer'], // TODO: remove pixi-gl-core + }, + }), + string({ + include: [ + 'src/**/*.frag', + 'src/**/*.vert', + ], + }), + replace({ + __VERSION__: pkg.version, + }), + preprocess({ + context: { + DEV: !prod, + DEVELOPMENT: !prod, + PROD: prod, + PRODUCTION: prod, + }, + }), + transpile(), + thaw(), +]; + +if (prod) +{ + plugins.push(uglify({ + mangle: true, + compress: true, + output: { + comments(node, comment) + { + const { value, type } = comment; + + return type === 'comment2' && value.indexOf(pkg.name) > -1; + }, + }, + }, minify)); +} + +let outro = ''; + +if (deprecated) +{ + const buffer = fs.readFileSync(path.resolve(deprecated), 'utf8'); + + outro = buble.transform(buffer).code; +} + +const compiled = (new Date()).toUTCString().replace(/GMT/g, 'UTC'); +const external = Object.keys(pkg.dependencies || []); +const sourcemap = true; +const name = 'PIXI'; +const banner = `/*! + * ${pkg.name} - v${pkg.version} + * Compiled ${compiled} + * + * ${pkg.name} is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */\n`; + +export default [ + { + banner, + outro, + name, + input, + output: { + file: pkg.main, + format: bundle ? 'umd' : 'cjs', + }, + external, + sourcemap, + plugins, + }, + { + banner, + input, + output: { + file: pkg.module, + format: 'es', + }, + external, + sourcemap, + plugins, + }, +]; diff --git a/bundles/pixi.js/package.json b/bundles/pixi.js/package.json index 090e4c5..2cb92ba 100644 --- a/bundles/pixi.js/package.json +++ b/bundles/pixi.js/package.json @@ -19,9 +19,9 @@ "url": "https://github.com/pixijs/pixi.js.git" }, "scripts": { - "build": "rollup -cp && rollup -cp -f umd", - "build:dev": "rollup -c && rollup -c -f umd", - "watch": "rollup -cw -f umd", + "build": "rollup -p -b -c node_modules/.bin/config -r src/deprecated.js", + "build:dev": "rollup -b -c node_modules/.bin/config -r src/deprecated.js", + "watch": "rollup -w -b -c node_modules/.bin/config -r src/deprecated.js", "postversion": "npm run build", "test": "tester" }, @@ -35,6 +35,8 @@ "@pixi/app": "^5.0.0-alpha", "@pixi/core": "^5.0.0-alpha", "@pixi/accessibility": "^5.0.0-alpha", + "@pixi/constants": "^5.0.0-alpha", + "@pixi/display": "^5.0.0-alpha", "@pixi/extract": "^5.0.0-alpha", "@pixi/filter-alpha": "^5.0.0-alpha", "@pixi/filter-blur": "^5.0.0-alpha", @@ -45,13 +47,16 @@ "@pixi/graphics": "^5.0.0-alpha", "@pixi/interaction": "^5.0.0-alpha", "@pixi/loaders": "^5.0.0-alpha", + "@pixi/math": "^5.0.0-alpha", "@pixi/mesh": "^5.0.0-alpha", "@pixi/mixin-cache-as-bitmap": "^5.0.0-alpha", "@pixi/mixin-get-child-by-name": "^5.0.0-alpha", "@pixi/mixin-get-global-position": "^5.0.0-alpha", + "@pixi/mixin-app-loader": "^5.0.0-alpha", "@pixi/particles": "^5.0.0-alpha", "@pixi/polyfill": "^5.0.0-alpha", "@pixi/prepare": "^5.0.0-alpha", + "@pixi/settings": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/spritesheet": "^5.0.0-alpha", "@pixi/sprite-animated": "^5.0.0-alpha", @@ -62,8 +67,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rimraf": "^2.6.2", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } diff --git a/bundles/pixi.js/rollup.config.js b/bundles/pixi.js/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/bundles/pixi.js/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js new file mode 100644 index 0000000..a529402 --- /dev/null +++ b/bundles/pixi.js/src/deprecated.js @@ -0,0 +1,226 @@ +// provide method to give a stack track for warnings +// useful for tracking-down where deprecated methods/properties/classes +// are being used within the code +function warn(msg) +{ + /* eslint-disable no-console */ + let stack = new Error().stack; + + // Handle IE < 10 and Safari < 6 + if (typeof stack === 'undefined') + { + console.warn('Deprecation Warning: ', msg); + } + else + { + // chop off the stack trace which includes pixi.js internal calls + stack = stack.split('\n').splice(3).join('\n'); + + if (console.groupCollapsed) + { + console.groupCollapsed( + '%cDeprecation Warning: %c%s', + 'color:#614108;background:#fffbe6', + 'font-weight:normal;color:#614108;background:#fffbe6', + msg + ); + console.warn(stack); + console.groupEnd(); + } + else + { + console.warn('Deprecation Warning: ', msg); + console.warn(stack); + } + } + /* eslint-enable no-console */ +} + +// Define via the exports +const PIXI = exports; + +Object.defineProperties(PIXI, { + /** + * @deprecated since 5.0.0 + * @see PIXI.ticker.UPDATE_PRIORITY + * @static + * @constant + * @name UPDATE_PRIORITY + * @memberof PIXI + * @type {object} + */ + UPDATE_PRIORITY: { + get() + { + warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); + + return PIXI.ticker.UPDATE_PRIORITY; + }, + }, + + /** + * @constant + * @name SVG_SIZE + * @memberof PIXI + * @see PIXI.SVGResource.SVG_SIZE + * @deprecated since 5.0.0 + */ + SVG_SIZE: { + get() + { + warn('PIXI.utils.SVG_SIZE has moved to PIXI.SVGResource.SVG_SIZE'); + + return PIXI.SVGResource.SVG_SIZE; + }, + }, +}); + +/** + * This namespace has been removed. All classes previous nested + * under this namespace have been moved to the top-level `PIXI` object. + * @namespace PIXI.extras + * @deprecated since 5.0.0 + */ +PIXI.extras = {}; + +Object.defineProperties(PIXI.extras, { + /** + * @class PIXI.extras.TilingSprite + * @see PIXI.TilingSprite + * @deprecated since 5.0.0 + */ + TilingSprite: { + get() + { + warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); + + return PIXI.TilingSprite; + }, + }, + /** + * @class PIXI.extras.TilingSpriteRenderer + * @see PIXI.TilingSpriteRenderer + * @deprecated since 5.0.0 + */ + TilingSpriteRenderer: { + get() + { + warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); + + return PIXI.TilingSpriteRenderer; + }, + }, + /** + * @class PIXI.extras.AnimatedSprite + * @see PIXI.AnimatedSprite + * @deprecated since 5.0.0 + */ + AnimatedSprite: { + get() + { + warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); + + return PIXI.AnimatedSprite; + }, + }, + /** + * @class PIXI.extras.BitmapText + * @see PIXI.BitmapText + * @deprecated since 5.0.0 + */ + BitmapText: { + get() + { + warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); + + return PIXI.BitmapText; + }, + }, +}); + +Object.defineProperties(PIXI.utils, { + /** + * @function PIXI.utils.getSvgSize + * @see PIXI.SVGResource.getSize + * @deprecated since 5.0.0 + */ + getSvgSize: { + get() + { + warn('PIXI.utils.getSvgSize has moved to PIXI.SVGResource.getSize'); + + return PIXI.SVGResource.getSize; + }, + }, +}); + +Object.defineProperties(PIXI.loaders.Loader, { + /** + * @function PIXI.loaders.Loader.addPixiMiddleware + * @see PIXI.loaders.Loader.useMiddleware + * @deprecated since 5.0.0 + */ + addPixiMiddleware: { + get() + { + warn('PIXI.loaders.Loader.addPixiMiddleware has moved to PIXI.loaders.Loader.useMiddleware'); + + return PIXI.loaders.Loader.useMiddleware; + }, + }, +}); + +Object.defineProperties(PIXI.loaders, { + /** + * @function PIXI.loaders.bitmapFontParser + * @see PIXI.BitmapFontLoader.middleware + * @deprecated since 5.0.0 + */ + bitmapFontParser: { + get() + { + warn('PIXI.loaders.bitmapFontParser has moved to PIXI.BitmapFontLoader.middleware'); + + return PIXI.BitmapFontLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.parseBitmapFontData + * @see PIXI.BitmapFontLoader.parse + * @deprecated since 5.0.0 + */ + parseBitmapFontData: { + get() + { + warn('PIXI.loaders.parseBitmapFontData has moved to PIXI.BitmapFontLoader.parse'); + + return PIXI.BitmapFontLoader.parse; + }, + }, + /** + * @function PIXI.loaders.spritesheetParser + * @see PIXI.SpritesheetLoader.middleware + * @deprecated since 5.0.0 + */ + spritesheetParser: { + get() + { + warn('PIXI.loaders.spritesheetParser has moved to PIXI.SpritesheetLoader.middleware'); + + return PIXI.SpritesheetLoader.middleware; + }, + }, + /** + * @function PIXI.loaders.getResourcePath + * @see PIXI.SpritesheetLoader.getResourcePath + * @deprecated since 5.0.0 + */ + getResourcePath: { + get() + { + warn('PIXI.loaders.getResourcePath has moved to PIXI.SpritesheetLoader.getResourcePath'); + + return PIXI.SpritesheetLoader.getResourcePath; + }, + }, +}); diff --git a/bundles/pixi.js/src/deprecation.js b/bundles/pixi.js/src/deprecation.js deleted file mode 100644 index 21249bd..0000000 --- a/bundles/pixi.js/src/deprecation.js +++ /dev/null @@ -1,92 +0,0 @@ -import { deprecationWarn as warn } from '@pixi/utils'; -import { UPDATE_PRIORITY } from '@pixi/ticker'; - -/** - * Internal deprecations - * @private - */ -export function deprecation(PIXI) -{ - /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - Object.defineProperties(PIXI, { - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return UPDATE_PRIORITY; - }, - }, - }); - - /** - * This namespace has been removed. All classes previous nested - * under this namespace have been moved to the top-level `PIXI` object. - * @namespace PIXI.extras - * @deprecated since 5.0.0 - */ - PIXI.extras = {}; - - Object.defineProperties(PIXI.extras, { - /** - * @class PIXI.extras.TilingSprite - * @see PIXI.TilingSprite - * @deprecated since 5.0.0 - */ - TilingSprite: { - get() - { - warn('PIXI.extras.TilingSprite has moved to PIXI.TilingSprite'); - - return PIXI.TilingSprite; - }, - }, - /** - * @class PIXI.extras.TilingSpriteRenderer - * @see PIXI.TilingSpriteRenderer - * @deprecated since 5.0.0 - */ - TilingSpriteRenderer: { - get() - { - warn('PIXI.extras.TilingSpriteRenderer has moved to PIXI.TilingSpriteRenderer'); - - return PIXI.TilingSpriteRenderer; - }, - }, - /** - * @class PIXI.extras.AnimatedSprite - * @see PIXI.AnimatedSprite - * @deprecated since 5.0.0 - */ - AnimatedSprite: { - get() - { - warn('PIXI.extras.AnimatedSprite has moved to PIXI.AnimatedSprite'); - - return PIXI.AnimatedSprite; - }, - }, - /** - * @class PIXI.extras.BitmapText - * @see PIXI.BitmapText - * @deprecated since 5.0.0 - */ - BitmapText: { - get() - { - warn('PIXI.extras.BitmapText has moved to PIXI.BitmapText'); - - return PIXI.BitmapText; - }, - }, - }); -} diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 216a7fc..2a9082c 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -11,6 +11,9 @@ export * from '@pixi/graphics'; export * from '@pixi/sprite-animated'; export * from '@pixi/sprite-tiling'; +export * from '@pixi/math'; +export * from '@pixi/constants'; +export * from '@pixi/display'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -21,17 +24,18 @@ import * as prepare from '@pixi/prepare'; // import * as particles from '@pixi/particles'; import * as filters from './filters'; +import * as utils from '@pixi/utils'; +import * as ticker from '@pixi/ticker'; +import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports import '@pixi/mixin-cache-as-bitmap'; import '@pixi/mixin-get-child-by-name'; import '@pixi/mixin-get-global-position'; - -import { deprecation } from './deprecation'; +import '@pixi/mixin-app-loader'; // handle mixins now, after all code has been added -import { mixins } from '@pixi/utils'; -mixins.performMixins(); +utils.mixins.performMixins(); /** * Alias for {@link PIXI.loaders.shared}. @@ -39,7 +43,7 @@ * @memberof PIXI * @type {PIXI.loader.Loader} */ -const loader = loaders.shared || null; +export const loader = loaders.shared; export { accessibility, @@ -50,11 +54,7 @@ mesh, // particles, prepare, - loader, + utils, + ticker, + settings, }; - -// Always export PixiJS globally. -global.PIXI = exports; // eslint-disable-line - -// Apply deprecations -deprecation(global.PIXI); diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 5a81a03..242a269 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,10 +1,18 @@ /* eslint-disable global-require */ -require('../'); +const PIXI = require('../'); describe('PIXI', function () { it('should exist as a global object', function () { - expect(PIXI).to.be.an('object'); + expect(PIXI).to.not.be.undefined; + expect(PIXI.interaction).to.not.be.undefined; + expect(PIXI.settings).to.not.be.undefined; + expect(PIXI.ticker).to.not.be.undefined; + expect(PIXI.loaders).to.not.be.undefined; + expect(PIXI.extract).to.not.be.undefined; + expect(PIXI.mesh).to.not.be.undefined; + expect(PIXI.prepare).to.not.be.undefined; + expect(PIXI.utils).to.not.be.undefined; }); }); diff --git a/filters/alpha/package.json b/filters/alpha/package.json index fe641b4..9a82979 100644 --- a/filters/alpha/package.json +++ b/filters/alpha/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/alpha/rollup.config.js b/filters/alpha/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/alpha/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/package.json b/filters/blur/package.json index cf18dce..182ce8b 100644 --- a/filters/blur/package.json +++ b/filters/blur/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/blur/rollup.config.js b/filters/blur/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/blur/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/blur/src/BlurYFilter.js b/filters/blur/src/BlurYFilter.js index f6869b6..c21d899 100644 --- a/filters/blur/src/BlurYFilter.js +++ b/filters/blur/src/BlurYFilter.js @@ -1,4 +1,5 @@ -import { Filter, settings } from '@pixi/core'; +import { Filter } from '@pixi/core'; +import { settings } from '@pixi/settings'; import generateBlurVertSource from './generateBlurVertSource'; import generateBlurFragSource from './generateBlurFragSource'; import getMaxBlurKernelSize from './getMaxBlurKernelSize'; diff --git a/filters/color-matrix/package.json b/filters/color-matrix/package.json index 30a40b3..f6c6efa 100644 --- a/filters/color-matrix/package.json +++ b/filters/color-matrix/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/color-matrix/rollup.config.js b/filters/color-matrix/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/color-matrix/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/displacement/package.json b/filters/displacement/package.json index 43ecf07..6a43832 100644 --- a/filters/displacement/package.json +++ b/filters/displacement/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/displacement/rollup.config.js b/filters/displacement/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/displacement/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/fxaa/package.json b/filters/fxaa/package.json index 31fa8d3..0ad2c29 100644 --- a/filters/fxaa/package.json +++ b/filters/fxaa/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/fxaa/rollup.config.js b/filters/fxaa/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/fxaa/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/filters/noise/package.json b/filters/noise/package.json index 2ed61fb..78b29b2 100644 --- a/filters/noise/package.json +++ b/filters/noise/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/filters/noise/rollup.config.js b/filters/noise/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/filters/noise/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/jsdoc.conf.json b/jsdoc.conf.json index 9beac7e..71f8cf5 100644 --- a/jsdoc.conf.json +++ b/jsdoc.conf.json @@ -5,7 +5,8 @@ "source": { "include": [ "bundles", - "packages" + "packages", + "filters" ], "excludePattern": "(node_modules|lib|dist|test)" }, diff --git a/packages/accessibility/package.json b/packages/accessibility/package.json index 99bbe2a..c08398e 100644 --- a/packages/accessibility/package.json +++ b/packages/accessibility/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -37,7 +37,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/accessibility/rollup.config.js b/packages/accessibility/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/accessibility/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/app/package.json b/packages/app/package.json index 9315df8..b8c2418 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "@pixi/utils": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/app/rollup.config.js b/packages/app/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/app/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/constants/package.json b/packages/constants/package.json index a386220..dc889d7 100644 --- a/packages/constants/package.json +++ b/packages/constants/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/constants/rollup.config.js b/packages/constants/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/constants/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/package.json b/packages/core/package.json index f9bce48..fd0d5b5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -33,7 +33,7 @@ "earcut": "^2.0.7", "eventemitter3": "^2.0.0", "ismobilejs": "^0.4.0", - "pixi-gl-core": "^1.0.3", + "pixi-gl-core": "^2.0.0-alpha", "mini-runner": "^1.0.1", "@pixi/math": "^5.0.0-alpha", "@pixi/constants": "^5.0.0-alpha", @@ -45,7 +45,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/core/rollup.config.js b/packages/core/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/core/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/core/src/geometry/Geometry.js b/packages/core/src/geometry/Geometry.js index 0faf3fc..15a526f 100644 --- a/packages/core/src/geometry/Geometry.js +++ b/packages/core/src/geometry/Geometry.js @@ -1,6 +1,7 @@ import Attribute from './Attribute'; import Buffer from './Buffer'; -import { interleaveTypedArrays, getBufferType } from '@pixi/utils'; +import interleaveTypedArrays from './utils/interleaveTypedArrays'; +import getBufferType from './utils/getBufferType'; const byteSizeMap = { 5126: 4, 5123: 2, 5121: 1 }; let UID = 0; diff --git a/packages/core/src/geometry/utils/getBufferType.js b/packages/core/src/geometry/utils/getBufferType.js new file mode 100644 index 0000000..cb988d7 --- /dev/null +++ b/packages/core/src/geometry/utils/getBufferType.js @@ -0,0 +1,33 @@ +export default function getBufferType(array) +{ + if (array.BYTES_PER_ELEMENT === 4) + { + if (array instanceof Float32Array) + { + return 'Float32Array'; + } + else if (array instanceof Uint32Array) + { + return 'Uint32Array'; + } + + return 'Int32Array'; + } + else if (array.BYTES_PER_ELEMENT === 2) + { + if (array instanceof Uint16Array) + { + return 'Uint16Array'; + } + } + else if (array.BYTES_PER_ELEMENT === 1) + { + if (array instanceof Uint8Array) + { + return 'Uint8Array'; + } + } + + // TODO map out the rest of the array elements! + return null; +} diff --git a/packages/core/src/geometry/utils/interleaveTypedArrays.js b/packages/core/src/geometry/utils/interleaveTypedArrays.js new file mode 100644 index 0000000..cce349d --- /dev/null +++ b/packages/core/src/geometry/utils/interleaveTypedArrays.js @@ -0,0 +1,54 @@ +import getBufferType from './getBufferType'; + +/* eslint-disable object-shorthand */ +const map = { + Float32Array: Float32Array, + Uint32Array: Uint32Array, + Int32Array: Int32Array, + Uint8Array: Uint8Array, +}; + +export default function interleaveTypedArrays(arrays, sizes) +{ + let outSize = 0; + let stride = 0; + const views = {}; + + for (let i = 0; i < arrays.length; i++) + { + stride += sizes[i]; + outSize += arrays[i].length; + } + + const buffer = new ArrayBuffer(outSize * 4); + + let out = null; + let littleOffset = 0; + + for (let i = 0; i < arrays.length; i++) + { + const size = sizes[i]; + const array = arrays[i]; + + const type = getBufferType(array); + + if (!views[type]) + { + views[type] = new map[type](buffer); + } + + out = views[type]; + + for (let j = 0; j < array.length; j++) + { + const indexStart = ((j / size | 0) * stride) + littleOffset; + const index = j % size; + + out[indexStart + index] = array[j]; + } + + littleOffset += size; + } + + return new Float32Array(buffer); +} diff --git a/packages/core/src/index.js b/packages/core/src/index.js index 0ec55dd..8383be7 100644 --- a/packages/core/src/index.js +++ b/packages/core/src/index.js @@ -13,22 +13,15 @@ */ export const VERSION = '__VERSION__'; -export * from '@pixi/math'; -export * from '@pixi/constants'; -export * from '@pixi/display'; - -import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; -import { settings } from '@pixi/settings'; -import CanvasRenderer from './renderers/canvas/CanvasRenderer'; -import WebGLRenderer from './renderers/webgl/WebGLRenderer'; - -export { settings, utils, ticker, CanvasRenderer, WebGLRenderer }; - +export { default as CanvasRenderer } from './renderers/canvas/CanvasRenderer'; +export { default as WebGLRenderer } from './renderers/webgl/WebGLRenderer'; export { default as FrameBuffer } from './textures/FrameBuffer'; export { default as CubeTexture } from './textures/CubeTexture'; export { default as BaseTexture } from './textures/BaseTexture'; export { default as ImageResource } from './textures/resources/ImageResource'; +export { default as CanvasResource } from './textures/resources/CanvasResource'; +export { default as SVGResource } from './textures/resources/SVGResource'; +export { default as VideoResource } from './textures/resources/VideoResource'; export { default as ArrayTexture } from './textures/ArrayTexture'; export { default as Texture } from './textures/Texture'; export { default as TextureMatrix } from './textures/TextureMatrix'; diff --git a/packages/core/src/renderers/SystemRenderer.js b/packages/core/src/renderers/SystemRenderer.js index 5ccb9b5..7f5a7db 100644 --- a/packages/core/src/renderers/SystemRenderer.js +++ b/packages/core/src/renderers/SystemRenderer.js @@ -187,6 +187,27 @@ * @private */ this._lastObjectRendered = this._tempDisplayObjectParent; + + /** + * Collection of plugins. + * @readonly + * @member {object} + */ + this.plugins = {}; + } + + /** + * Initialize the plugins. + * + * @protected + * @param {object} staticMap - The dictionary of staticly saved plugins. + */ + initPlugins(staticMap) + { + for (const o in staticMap) + { + this.plugins[o] = new (staticMap[o])(this); + } } /** @@ -265,11 +286,19 @@ */ destroy(removeView) { + for (const o in this.plugins) + { + this.plugins[o].destroy(); + this.plugins[o] = null; + } + if (removeView && this.view.parentNode) { this.view.parentNode.removeChild(this.view); } + this.plugins = null; + this.type = RENDERER_TYPE.UNKNOWN; this.view = null; diff --git a/packages/core/src/renderers/canvas/CanvasRenderer.js b/packages/core/src/renderers/canvas/CanvasRenderer.js index 37ffdce..38a7a44 100644 --- a/packages/core/src/renderers/canvas/CanvasRenderer.js +++ b/packages/core/src/renderers/canvas/CanvasRenderer.js @@ -2,7 +2,6 @@ import CanvasMaskManager from './utils/CanvasMaskManager'; import CanvasRenderTarget from './utils/CanvasRenderTarget'; import mapCanvasBlendModesToPixi from './utils/mapCanvasBlendModesToPixi'; -import { pluginTarget } from '@pixi/utils'; import { RENDERER_TYPE, SCALE_MODES, BLEND_MODES } from '@pixi/constants'; import { settings } from '@pixi/settings'; @@ -98,7 +97,7 @@ } } - this.initPlugins(); + this.initPlugins(CanvasRenderer.__plugins); this.blendModes = mapCanvasBlendModesToPixi(); this._activeBlendMode = null; @@ -288,8 +287,6 @@ */ destroy(removeView) { - this.destroyPlugins(); - // call the base destroy super.destroy(removeView); @@ -330,27 +327,30 @@ { this._activeBlendMode = this.blendModes.indexOf(this.context.globalCompositeOperation); } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.CanvasRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + CanvasRenderer.__plugins = CanvasRenderer.__plugins || {}; + CanvasRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.CanvasRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.CanvasExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.CanvasPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.CanvasRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(CanvasRenderer); diff --git a/packages/core/src/renderers/webgl/WebGLRenderer.js b/packages/core/src/renderers/webgl/WebGLRenderer.js index c36e138..f57f6ba 100644 --- a/packages/core/src/renderers/webgl/WebGLRenderer.js +++ b/packages/core/src/renderers/webgl/WebGLRenderer.js @@ -1,5 +1,5 @@ import SystemRenderer from '../SystemRenderer'; -import { sayHello, pluginTarget } from '@pixi/utils'; +import { sayHello } from '@pixi/utils'; import MaskSystem from './systems/MaskSystem'; import StencilSystem from './systems/StencilSystem'; import FilterSystem from './systems/FilterSystem'; @@ -107,7 +107,8 @@ .addSystem(RenderTextureSystem, 'renderTexture') .addSystem(BatchSystem, 'batch'); - this.initPlugins(); + this.initPlugins(WebGLRenderer.__plugins); + /** * The options passed in to create a new webgl context. * @@ -292,27 +293,30 @@ // TODO nullify all the managers.. this.gl = null; } + + /** + * Collection of installed plugins. These are included by default in PIXI, but can be excluded + * by creating a custom build. Consult the README for more information about creating custom + * builds and excluding plugins. + * @name PIXI.WebGLRenderer#plugins + * @type {object} + * @readonly + * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. + * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. + * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. + * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. + */ + + /** + * Adds a plugin to the renderer. + * + * @method + * @param {string} pluginName - The name of the plugin. + * @param {Function} ctor - The constructor function or class for the plugin. + */ + static registerPlugin(pluginName, ctor) + { + WebGLRenderer.__plugins = WebGLRenderer.__plugins || {}; + WebGLRenderer.__plugins[pluginName] = ctor; + } } - -/** - * Collection of installed plugins. These are included by default in PIXI, but can be excluded - * by creating a custom build. Consult the README for more information about creating custom - * builds and excluding plugins. - * @name PIXI.WebGLRenderer#plugins - * @type {object} - * @readonly - * @property {PIXI.accessibility.AccessibilityManager} accessibility Support tabbing interactive elements. - * @property {PIXI.extract.WebGLExtract} extract Extract image data from renderer. - * @property {PIXI.interaction.InteractionManager} interaction Handles mouse, touch and pointer events. - * @property {PIXI.prepare.WebGLPrepare} prepare Pre-render display objects. - */ - -/** - * Adds a plugin to the renderer. - * - * @method PIXI.WebGLRenderer#registerPlugin - * @param {string} pluginName - The name of the plugin. - * @param {Function} ctor - The constructor function or class for the plugin. - */ - -pluginTarget.mixin(WebGLRenderer); diff --git a/packages/core/src/shader/Program.js b/packages/core/src/shader/Program.js index bd566a5..19d1527 100644 --- a/packages/core/src/shader/Program.js +++ b/packages/core/src/shader/Program.js @@ -1,6 +1,7 @@ import extractUniformsFromSrc from './extractUniformsFromSrc'; import * as shaderUtils from '../renderers/webgl/systems/shader/shader'; -import { ProgramCache, getTestContext } from '@pixi/utils'; +import { ProgramCache } from '@pixi/utils'; +import getTestContext from './getTestContext'; import defaultFragment from './defaultProgram.frag'; import defaultVertex from './defaultProgram.vert'; diff --git a/packages/core/src/shader/getTestContext.js b/packages/core/src/shader/getTestContext.js new file mode 100644 index 0000000..ea174cc --- /dev/null +++ b/packages/core/src/shader/getTestContext.js @@ -0,0 +1,48 @@ +import { settings } from '@pixi/settings'; + +let context = null; + +/** + * returns a little webGL context to use for program inspection. + * + * @static + * @private + * @returns {webGL-context} a gl context to test with + */ +export default function getTestContext() +{ + if (!context) + { + const canvas = document.createElement('canvas'); + + let gl; + + if (settings.PREFER_WEBGL_2) + { + gl = canvas.getContext('webgl2', {}); + } + + if (!gl) + { + gl = canvas.getContext('webgl', {}) + || canvas.getContext('experimental-webgl', {}); + + if (!gl) + { + // fail, not able to get a context + throw new Error('This browser does not support webGL. Try using the canvas renderer'); + } + else + { + // for shader testing.. + gl.getExtension('WEBGL_draw_buffers'); + } + } + + context = gl; + + return gl; + } + + return context; +} diff --git a/packages/core/src/textures/resources/CanvasResource.js b/packages/core/src/textures/resources/CanvasResource.js index 9a1a871..14914c5 100644 --- a/packages/core/src/textures/resources/CanvasResource.js +++ b/packages/core/src/textures/resources/CanvasResource.js @@ -1,5 +1,12 @@ import TextureResource from './TextureResource'; +/** + * Resource type for HTMLCanvasElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLCanvasElement} source - Canvas element to use + */ export default class CanvasResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/ImageResource.js b/packages/core/src/textures/resources/ImageResource.js index 3e51c95..bfae6cf 100644 --- a/packages/core/src/textures/resources/ImageResource.js +++ b/packages/core/src/textures/resources/ImageResource.js @@ -1,6 +1,13 @@ import { determineCrossOrigin } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for HTMLImageElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLImageElement} source - Image element to use + */ export default class ImageResource extends TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/SVGResource.js b/packages/core/src/textures/resources/SVGResource.js index 775b8a6..307b908 100644 --- a/packages/core/src/textures/resources/SVGResource.js +++ b/packages/core/src/textures/resources/SVGResource.js @@ -1,14 +1,22 @@ -import { decomposeDataUri, getSvgSize, uid } from '@pixi/utils'; +import { decomposeDataUri, uid } from '@pixi/utils'; import TextureResource from './TextureResource'; +/** + * Resource type for SVG elements and graphics. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {SVGResource} svgSource - Source SVG element. + * @param {number} [scale=1] Scale to apply to SVG. + */ export default class SVGResource extends TextureResource { - constructor(svgSource, scale) + constructor(svgSource, scale = 1) { super(); this.svgSource = svgSource; - this.scale = 1 || scale; + this.scale = scale; this.uploadable = true; this.resolve = null; @@ -23,6 +31,8 @@ /** * Checks if `source` is an SVG image and whether it's loaded via a URL or a data URI. Then calls * `_loadSvgSourceUsingDataUri` or `_loadSvgSourceUsingXhr`. + * + * @private */ _loadSvgSource() { @@ -41,6 +51,8 @@ /** * Loads an SVG string from `imageUrl` using XHR and then calls `_loadSvgSourceUsingString`. + * + * @private */ _loadSvgSourceUsingXhr() { @@ -74,13 +86,14 @@ * created canvas is the new `source`. The SVG is scaled using `sourceScale`. Called by * `_loadSvgSourceUsingXhr` or `_loadSvgSourceUsingDataUri`. * + * @private * @param {string} svgString SVG source as string * * @fires loaded */ _loadSvgSourceUsingString(svgString) { - const svgSize = getSvgSize(svgString); + const svgSize = SVGResource.getSize(svgString); // TODO do we need to wait for this to load? // seems instant! @@ -118,8 +131,58 @@ this.resolve(this); } + /** + * Typedef for Size object. + * + * @typedef {object} PIXI.SVGResource~Size + * @property {number} width - Width component + * @property {number} height - Height component + */ + + /** + * Get size from an svg string using regexp. + * + * @method + * @param {string} svgString - a serialized svg element + * @return {PIXI.SVGResource~Size} image extension + */ + static getSize(svgString) + { + const sizeMatch = SVGResource.SVG_SIZE.exec(svgString); + const size = {}; + + if (sizeMatch) + { + size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); + size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); + } + + return size; + } + static from(url) { return new SVGResource(url); } } + +/** + * List of common SVG file extensions supported by SVGResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +SVGResource.TYPES = ['svg']; + +/** + * RegExp for SVG size. + * + * @static + * @constant + * @name SVG_SIZE + * @memberof PIXI.SVGResource + * @type {RegExp|string} + * @example <svg width="100" height="100"></svg> + */ +SVGResource.SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/core/src/textures/resources/TextureResource.js b/packages/core/src/textures/resources/TextureResource.js index 7516c1e..5c5f2be 100644 --- a/packages/core/src/textures/resources/TextureResource.js +++ b/packages/core/src/textures/resources/TextureResource.js @@ -1,5 +1,11 @@ import Runner from 'mini-runner'; +/** + * Base Texture resource class. + * @class + * @memberof PIXI + * @param {any} source - Source element to use. + */ export default class TextureResource { constructor(source) diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index a01dd1a..61311e8 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,6 +1,13 @@ import TextureResource from './TextureResource'; import { shared } from '@pixi/ticker'; +/** + * Resource type for HTMLVideoElement. + * @class + * @extends PIXI.TextureResource + * @memberof PIXI + * @param {HTMLVideoElement} source - Video element to use. + */ export default class VideoResource extends TextureResource { constructor(source) @@ -254,3 +261,12 @@ return source; } + +/** + * List of common video file extensions supported by VideoResource. + * @constant + * @member {Array} + * @static + * @readonly + */ +VideoResource.TYPES = ['mp4', 'm4v', 'webm', 'ogg', 'ogv', 'h264', 'avi', 'mov']; diff --git a/packages/core/src/textures/resources/createResource.js b/packages/core/src/textures/resources/createResource.js index 01f88a0..ce437b2 100644 --- a/packages/core/src/textures/resources/createResource.js +++ b/packages/core/src/textures/resources/createResource.js @@ -7,18 +7,21 @@ { if (typeof source === 'string') { - // check if its a video.. - if (source.match(/\.(mp4|webm|ogg|h264|avi|mov)$/)) + // search for file extension: period, 3-4 chars, then ?, # or EOL + const result = (/\.(\w{3,4})(?:$|\?|#)/i).exec(source); + + if (result) { - return new VideoResource.fromUrl(source); - // video! - // return Texture.fromVideoUrl(source); - // return SVGResource.from(url); - } - else if (source.match(/\.(svg)$/)) - { - // SVG - return SVGResource.from(source); + const extension = result[1].toLowerCase(); + + if (VideoResource.TYPES.indexOf(extension) > -1) + { + return new VideoResource.fromUrl(source); + } + else if (SVGResource.TYPES.indexOf(extension) > -1) + { + return SVGResource.from(source); + } } // probably an image! diff --git a/packages/core/test/SVGResource.js b/packages/core/test/SVGResource.js new file mode 100644 index 0000000..d8e5147 --- /dev/null +++ b/packages/core/test/SVGResource.js @@ -0,0 +1,57 @@ +const { SVGResource } = require('../'); + +describe('PIXI.SVGResource', function () +{ + describe('getSize', function () + { + it('should exist', function () + { + expect(SVGResource.getSize) + .to.be.a('function'); + }); + + it('should return a size object with width and height from an SVG string', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return a size object from an SVG string with inverted quotes', function () + { + const svgSize = SVGResource.getSize(""); // eslint-disable-line quotes + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should work with px values', function () + { + const svgSize = SVGResource.getSize(''); + + expect(svgSize) + .to.be.an('object'); + expect(svgSize.width) + .to.equal(64); + expect(svgSize.height) + .to.equal(32); + }); + + it('should return an empty object when width and/or height is missing', function () + { + const svgSize = SVGResource.getSize(''); + + expect(Object.keys(svgSize).length) + .to.equal(0); + }); + }); +}); diff --git a/packages/core/test/index.js b/packages/core/test/index.js index b91975c..efcb541 100644 --- a/packages/core/test/index.js +++ b/packages/core/test/index.js @@ -2,3 +2,4 @@ require('./CanvasRenderer'); require('./Texture'); require('./WebGLRenderer'); +require('./SVGResource'); diff --git a/packages/display/package.json b/packages/display/package.json index cd9ddf5..22978b1 100644 --- a/packages/display/package.json +++ b/packages/display/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/display/rollup.config.js b/packages/display/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/display/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/extract/package.json b/packages/extract/package.json index ee5f45c..f103c91 100644 --- a/packages/extract/package.json +++ b/packages/extract/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,7 +34,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/extract/rollup.config.js b/packages/extract/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/extract/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/fragments/package.json b/packages/fragments/package.json index 76304af..e84be17 100644 --- a/packages/fragments/package.json +++ b/packages/fragments/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/fragments/rollup.config.js b/packages/fragments/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/fragments/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/graphics/package.json b/packages/graphics/package.json index 7cc544a..3ad61af 100644 --- a/packages/graphics/package.json +++ b/packages/graphics/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/graphics/rollup.config.js b/packages/graphics/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/graphics/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/interaction/package.json b/packages/interaction/package.json index bfc4e26..e0da44b 100644 --- a/packages/interaction/package.json +++ b/packages/interaction/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "@pixi/graphics": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/interaction/rollup.config.js b/packages/interaction/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/interaction/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/package.json b/packages/loaders/package.json index 3746792..0ccf266 100644 --- a/packages/loaders/package.json +++ b/packages/loaders/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,16 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", - "@pixi/app": "^5.0.0-alpha", - "@pixi/spritesheet": "^5.0.0-alpha", - "@pixi/text-bitmap": "^5.0.0-alpha", "resource-loader": "^2.0.9", "eventemitter3": "^2.0.0" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/loaders/rollup.config.js b/packages/loaders/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/loaders/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/loaders/src/Loader.js b/packages/loaders/src/Loader.js new file mode 100644 index 0000000..6f6e9bd --- /dev/null +++ b/packages/loaders/src/Loader.js @@ -0,0 +1,144 @@ +import ResourceLoader from 'resource-loader'; +import EventEmitter from 'eventemitter3'; +import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; +import textureParser from './textureParser'; + +/** + * + * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader + * + * ```js + * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. + * //or + * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want + * + * const sprites = {}; + * + * // Chainable `add` to enqueue a resource + * loader.add('bunny', 'data/bunny.png') + * .add('spaceship', 'assets/spritesheet.json'); + * loader.add('scoreFont', 'assets/score.fnt'); + * + * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. + * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). + * loader.pre(cachingMiddleware); + * + * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. + * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). + * loader.use(parsingMiddleware); + * + * // The `load` method loads the queue of resources, and calls the passed in callback called once all + * // resources have loaded. + * loader.load((loader, resources) => { + * // resources is an object where the key is the name of the resource loaded and the value is the resource object. + * // They have a couple default properties: + * // - `url`: The URL that the resource was loaded from + * // - `error`: The error that happened when trying to load (if any) + * // - `data`: The raw data that was loaded + * // also may contain other properties based on the middleware that runs. + * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); + * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); + * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); + * }); + * + * // throughout the process multiple signals can be dispatched. + * loader.onProgress.add(() => {}); // called once per loaded/errored file + * loader.onError.add(() => {}); // called once per errored file + * loader.onLoad.add(() => {}); // called once per loaded file + * loader.onComplete.add(() => {}); // called once when the queued resources all load. + * ``` + * + * @see https://github.com/englercj/resource-loader + * + * @class Loader + * @extends module:resource-loader.ResourceLoader + * @memberof PIXI.loaders + * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. + * @param {number} [concurrency=10] - The number of resources to load concurrently. + */ +export class Loader extends ResourceLoader +{ + constructor(baseUrl, concurrency) + { + super(baseUrl, concurrency); + EventEmitter.call(this); + + for (let i = 0; i < Loader._middleware.length; ++i) + { + this.use(Loader._middleware[i]()); + } + + // Compat layer, translate the new v2 signals into old v1 events. + this.onStart.add((l) => this.emit('start', l)); + this.onProgress.add((l, r) => this.emit('progress', l, r)); + this.onError.add((e, l, r) => this.emit('error', e, l, r)); + this.onLoad.add((l, r) => this.emit('load', l, r)); + this.onComplete.add((l, r) => this.emit('complete', l, r)); + + /** + * If this loader cannot be destroyed. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + } + + /** + * Destroy the loader, removes references. + */ + destroy() + { + if (!this._protected) + { + this.removeAllListeners(); + this.reset(); + } + } +} + +// Copy EE3 prototype (mixin) +Object.assign(Loader.prototype, EventEmitter.prototype); + +/** + * Collection of all installed middleware for Loader. + * + * @static + * @member {Array} + * @memberof PIXI.loaders.Loader + * @private + */ +Loader._middleware = []; + +/** + * A premade instance of the loader that can be used to load resources. + * @name shared + * @memberof PIXI.loaders + * @type {PIXI.loaders.Loader} + */ +export const shared = new Loader(); +shared._protected = true; + +/** + * Adds a middleware for the global shared loader and all + * new Loader instances created. + * + * @static + * @method useMiddleware + * @memberof PIXI.loaders.Loader + * @param {Function} fn - The middleware to add. + */ +Loader.useMiddleware = function useMiddleware(fn) +{ + // Install for current shared loader + shared.use(fn); + + // Install for all future loaders + Loader._middleware.push(fn); +}; + +// parse any blob into more usable objects (e.g. Image) +Loader.useMiddleware(blobMiddlewareFactory); + +// parse any Image objects into textures +Loader.useMiddleware(textureParser); diff --git a/packages/loaders/src/bitmapFontParser.js b/packages/loaders/src/bitmapFontParser.js deleted file mode 100644 index 1e4fa1d..0000000 --- a/packages/loaders/src/bitmapFontParser.js +++ /dev/null @@ -1,95 +0,0 @@ -import * as path from 'path'; -import { TextureCache } from '@pixi/utils'; -import { Resource } from 'resource-loader'; -import { BitmapText } from '@pixi/text-bitmap'; - -/** - * Register a BitmapText font from loader resource. - * - * @function parseBitmapFontData - * @memberof PIXI.loaders - * @param {PIXI.loaders.Resource} resource - Loader resource. - * @param {PIXI.Texture} texture - Reference to texture. - */ -export function parse(resource, texture) -{ - resource.bitmapFont = BitmapText.registerFont(resource.data, texture); -} - -export default function () -{ - return function bitmapFontParser(resource, next) - { - // skip if no data or not xml data - if (!resource.data || resource.type !== Resource.TYPE.XML) - { - next(); - - return; - } - - // skip if not bitmap font data, using some silly duck-typing - if (resource.data.getElementsByTagName('page').length === 0 - || resource.data.getElementsByTagName('info').length === 0 - || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null - ) - { - next(); - - return; - } - - let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; - - if (resource.isDataUrl) - { - if (xmlUrl === '.') - { - xmlUrl = ''; - } - - if (this.baseUrl && xmlUrl) - { - // if baseurl has a trailing slash then add one to xmlUrl so the replace works below - if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') - { - xmlUrl += '/'; - } - } - } - - // remove baseUrl from xmlUrl - xmlUrl = xmlUrl.replace(this.baseUrl, ''); - - // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. - if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') - { - xmlUrl += '/'; - } - - const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); - - if (TextureCache[textureUrl]) - { - // reuse existing texture - parse(resource, TextureCache[textureUrl]); - next(); - } - else - { - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - // load the texture for the font - this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => - { - parse(resource, res.texture); - next(); - }); - } - }; -} diff --git a/packages/loaders/src/index.js b/packages/loaders/src/index.js index cff0c9e..8e816cc 100644 --- a/packages/loaders/src/index.js +++ b/packages/loaders/src/index.js @@ -1,5 +1,11 @@ -import { Application } from '@pixi/app'; -import Loader from './loader'; +/** + * Reference to **{@link https://github.com/englercj/resource-loader + * resource-loader}**'s Resource class. + * @see http://englercj.github.io/resource-loader/Resource.html + * @class Resource + * @memberof PIXI.loaders + */ +export { Resource } from 'resource-loader'; /** * This namespace contains APIs which extends the {@link https://github.com/englercj/resource-loader resource-loader} module @@ -14,67 +20,5 @@ * }); * @namespace PIXI.loaders */ -export { Loader }; -export { default as bitmapFontParser, parse as parseBitmapFontData } from './bitmapFontParser'; -export { default as spritesheetParser, getResourcePath } from './spritesheetParser'; +export { Loader, shared } from './Loader'; export { default as textureParser } from './textureParser'; - -/** - * Reference to **resource-loader**'s Resource class. - * See https://github.com/englercj/resource-loader - * @class Resource - * @memberof PIXI.loaders - */ -export { Resource } from 'resource-loader'; - -/** - * A premade instance of the loader that can be used to load resources. - * @name shared - * @memberof PIXI.loaders - * @type {PIXI.loaders.Loader} - */ -const shared = new Loader(); - -shared.destroy = () => -{ - // protect destroying shared loader -}; - -export { shared }; - -// Mixin the loader construction -const AppPrototype = Application.prototype; - -AppPrototype._loader = null; - -/** - * Loader instance to help with asset loading. - * @name PIXI.Application#loader - * @type {PIXI.loaders.Loader} - */ -Object.defineProperty(AppPrototype, 'loader', { - get() - { - if (!this._loader) - { - const sharedLoader = this._options.sharedLoader; - - this._loader = sharedLoader ? shared : new Loader(); - } - - return this._loader; - }, -}); - -// Override the destroy function -// making sure to destroy the current Loader -AppPrototype._parentDestroy = AppPrototype.destroy; -AppPrototype.destroy = function destroy(removeView) -{ - if (this._loader) - { - this._loader.destroy(); - this._loader = null; - } - this._parentDestroy(removeView); -}; diff --git a/packages/loaders/src/loader.js b/packages/loaders/src/loader.js deleted file mode 100644 index 93356a3..0000000 --- a/packages/loaders/src/loader.js +++ /dev/null @@ -1,124 +0,0 @@ -import ResourceLoader from 'resource-loader'; -import { blobMiddlewareFactory } from 'resource-loader/lib/middlewares/parsing/blob'; -import EventEmitter from 'eventemitter3'; -import textureParser from './textureParser'; -import spritesheetParser from './spritesheetParser'; -import bitmapFontParser from './bitmapFontParser'; - -/** - * - * The new loader, extends Resource Loader by Chad Engler: https://github.com/englercj/resource-loader - * - * ```js - * const loader = PIXI.loader; // PixiJS exposes a premade instance for you to use. - * //or - * const loader = new PIXI.loaders.Loader(); // you can also create your own if you want - * - * const sprites = {}; - * - * // Chainable `add` to enqueue a resource - * loader.add('bunny', 'data/bunny.png') - * .add('spaceship', 'assets/spritesheet.json'); - * loader.add('scoreFont', 'assets/score.fnt'); - * - * // Chainable `pre` to add a middleware that runs for each resource, *before* loading that resource. - * // This is useful to implement custom caching modules (using filesystem, indexeddb, memory, etc). - * loader.pre(cachingMiddleware); - * - * // Chainable `use` to add a middleware that runs for each resource, *after* loading that resource. - * // This is useful to implement custom parsing modules (like spritesheet parsers, spine parser, etc). - * loader.use(parsingMiddleware); - * - * // The `load` method loads the queue of resources, and calls the passed in callback called once all - * // resources have loaded. - * loader.load((loader, resources) => { - * // resources is an object where the key is the name of the resource loaded and the value is the resource object. - * // They have a couple default properties: - * // - `url`: The URL that the resource was loaded from - * // - `error`: The error that happened when trying to load (if any) - * // - `data`: The raw data that was loaded - * // also may contain other properties based on the middleware that runs. - * sprites.bunny = new PIXI.TilingSprite(resources.bunny.texture); - * sprites.spaceship = new PIXI.TilingSprite(resources.spaceship.texture); - * sprites.scoreFont = new PIXI.TilingSprite(resources.scoreFont.texture); - * }); - * - * // throughout the process multiple signals can be dispatched. - * loader.onProgress.add(() => {}); // called once per loaded/errored file - * loader.onError.add(() => {}); // called once per errored file - * loader.onLoad.add(() => {}); // called once per loaded file - * loader.onComplete.add(() => {}); // called once when the queued resources all load. - * ``` - * - * @see https://github.com/englercj/resource-loader - * - * @class - * @extends module:resource-loader.ResourceLoader - * @memberof PIXI.loaders - */ -export default class Loader extends ResourceLoader -{ - /** - * @param {string} [baseUrl=''] - The base url for all resources loaded by this loader. - * @param {number} [concurrency=10] - The number of resources to load concurrently. - */ - constructor(baseUrl, concurrency) - { - super(baseUrl, concurrency); - EventEmitter.call(this); - - for (let i = 0; i < Loader._pixiMiddleware.length; ++i) - { - this.use(Loader._pixiMiddleware[i]()); - } - - // Compat layer, translate the new v2 signals into old v1 events. - this.onStart.add((l) => this.emit('start', l)); - this.onProgress.add((l, r) => this.emit('progress', l, r)); - this.onError.add((e, l, r) => this.emit('error', e, l, r)); - this.onLoad.add((l, r) => this.emit('load', l, r)); - this.onComplete.add((l, r) => this.emit('complete', l, r)); - } - - /** - * Adds a default middleware to the PixiJS loader. - * - * @static - * @param {Function} fn - The middleware to add. - */ - static addPixiMiddleware(fn) - { - Loader._pixiMiddleware.push(fn); - } - - /** - * Destroy the loader, removes references. - */ - destroy() - { - this.removeAllListeners(); - this.reset(); - } -} - -// Copy EE3 prototype (mixin) -for (const k in EventEmitter.prototype) -{ - Loader.prototype[k] = EventEmitter.prototype[k]; -} - -Loader._pixiMiddleware = [ - // parse any blob into more usable objects (e.g. Image) - blobMiddlewareFactory, - // parse any Image objects into textures - textureParser, - // parse any spritesheet data into multiple textures - spritesheetParser, - // parse bitmap font data into multiple textures - bitmapFontParser, -]; - -// Add custom extentions -const Resource = ResourceLoader.Resource; - -Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); diff --git a/packages/loaders/src/spritesheetParser.js b/packages/loaders/src/spritesheetParser.js deleted file mode 100644 index f7fa206..0000000 --- a/packages/loaders/src/spritesheetParser.js +++ /dev/null @@ -1,60 +0,0 @@ -import { Resource } from 'resource-loader'; -import url from 'url'; -import { Spritesheet } from '@pixi/spritesheet'; - -export default function () -{ - return function spritesheetParser(resource, next) - { - const imageResourceName = `${resource.name}_image`; - - // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists - if (!resource.data - || resource.type !== Resource.TYPE.JSON - || !resource.data.frames - || this.resources[imageResourceName] - ) - { - next(); - - return; - } - - const loadOptions = { - crossOrigin: resource.crossOrigin, - loadType: Resource.LOAD_TYPE.IMAGE, - metadata: resource.metadata.imageMetadata, - parentResource: resource, - }; - - const resourcePath = getResourcePath(resource, this.baseUrl); - - // load the image for this sheet - this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) - { - const spritesheet = new Spritesheet( - res.texture.baseTexture, - resource.data, - resource.url - ); - - spritesheet.parse(() => - { - resource.spritesheet = spritesheet; - resource.textures = spritesheet.textures; - next(); - }); - }); - }; -} - -export function getResourcePath(resource, baseUrl) -{ - // Prepend url path unless the resource image is a data url - if (resource.isDataUrl) - { - return resource.data.meta.image; - } - - return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); -} diff --git a/packages/loaders/test/bitmapFontParser.js b/packages/loaders/test/bitmapFontParser.js deleted file mode 100644 index 43ef194..0000000 --- a/packages/loaders/test/bitmapFontParser.js +++ /dev/null @@ -1,325 +0,0 @@ -const path = require('path'); -const fs = require('fs'); -const { BitmapText } = require('@pixi/text-bitmap'); -const { BaseTextureCache, TextureCache } = require('@pixi/utils'); -const { Texture, BaseTexture } = require('@pixi/core'); -const { Spritesheet } = require('@pixi/spritesheet'); -const { bitmapFontParser, parseBitmapFontData } = require('../'); - -describe('PIXI.loaders.bitmapFontParser', function () -{ - afterEach(function () - { - for (const font in BitmapText.fonts) - { - delete BitmapText.fonts[font]; - } - for (const baseTexture in BaseTextureCache) - { - delete BaseTextureCache[baseTexture]; - } - for (const texture in TextureCache) - { - delete TextureCache[texture]; - } - }); - - before(function (done) - { - const resolveURL = (url) => path.resolve(this.resources, url); - - this.resources = path.join(__dirname, 'resources'); - this.fontXML = null; - this.fontScaledXML = null; - this.fontImage = null; - this.fontScaledImage = null; - this.atlasImage = null; - this.atlasScaledImage = null; - this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require - this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require - - const loadXML = (url) => new Promise((resolve) => - fs.readFile(resolveURL(url), 'utf8', (err, data) => - { - expect(err).to.be.null; - resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); - })); - - const loadImage = (url) => new Promise((resolve) => - { - const image = new Image(); - - image.onload = () => resolve(image); - image.src = resolveURL(url); - }); - - Promise.all([ - loadXML('font.fnt'), - loadXML('font@0.5x.fnt'), - loadImage('font.png'), - loadImage('font@0.5x.png'), - loadImage('atlas.png'), - loadImage('atlas@0.5x.png'), - ]).then(([ - fontXML, - fontScaledXML, - fontImage, - fontScaledImage, - atlasImage, - atlasScaledImage, - ]) => - { - this.fontXML = fontXML; - this.fontScaledXML = fontScaledXML; - this.fontImage = fontImage; - this.fontScaledImage = fontScaledImage; - this.atlasImage = atlasImage; - this.atlasScaledImage = atlasScaledImage; - done(); - }); - }); - - it('should exist and return a function', function () - { - expect(bitmapFontParser).to.be.a('function'); - expect(bitmapFontParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not XML', function () - { - const spy = sinon.spy(); - const res = {}; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is not properly formatted XML', function () - { - const spy = sinon.spy(); - const res = { data: document.createDocumentFragment() }; - - bitmapFontParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - // TODO: Test the texture cache code path. - // TODO: Test the loading texture code path. - // TODO: Test data-url code paths. - - it('should properly register bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); - const font = BitmapText.registerFont(this.fontXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charA.texture.frame.x).to.equal(2); - expect(charA.texture.frame.y).to.equal(2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charB.texture.frame.x).to.equal(2); - expect(charB.texture.frame.y).to.equal(24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charC.texture.frame.x).to.equal(23); - expect(charC.texture.frame.y).to.equal(2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); - expect(charD.texture.frame.x).to.equal(19); - expect(charD.texture.frame.y).to.equal(24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register SCALED bitmap font', function (done) - { - const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); - const font = BitmapText.registerFont(this.fontScaledXML, texture); - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 - expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 - expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 - expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 - expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 - expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 - expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); - expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 - expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 - expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 - expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - - it('should properly register bitmap font NESTED into spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); - - it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) - { - const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); - const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); - - spritesheet.resolution = 1; - - spritesheet.parse(() => - { - const fontTexture = Texture.fromFrame('resources/font.png'); - const font = BitmapText.registerFont(this.fontXML, fontTexture); - const fontX = 158; // bare value from spritesheet frame - const fontY = 2; // bare value from spritesheet frame - - expect(font).to.be.an.object; - expect(BitmapText.fonts.font).to.equal(font); - expect(font).to.have.property('chars'); - const charA = font.chars['A'.charCodeAt(0) || 65]; - - expect(charA).to.exist; - expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charA.texture.frame.x).to.equal(fontX + 2); - expect(charA.texture.frame.y).to.equal(fontY + 2); - expect(charA.texture.frame.width).to.equal(19); - expect(charA.texture.frame.height).to.equal(20); - const charB = font.chars['B'.charCodeAt(0) || 66]; - - expect(charB).to.exist; - expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charB.texture.frame.x).to.equal(fontX + 2); - expect(charB.texture.frame.y).to.equal(fontY + 24); - expect(charB.texture.frame.width).to.equal(15); - expect(charB.texture.frame.height).to.equal(20); - const charC = font.chars['C'.charCodeAt(0) || 67]; - - expect(charC).to.exist; - expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charC.texture.frame.x).to.equal(fontX + 23); - expect(charC.texture.frame.y).to.equal(fontY + 2); - expect(charC.texture.frame.width).to.equal(18); - expect(charC.texture.frame.height).to.equal(20); - const charD = font.chars['D'.charCodeAt(0) || 68]; - - expect(charD).to.exist; - expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); - expect(charD.texture.frame.x).to.equal(fontX + 19); - expect(charD.texture.frame.y).to.equal(fontY + 24); - expect(charD.texture.frame.width).to.equal(17); - expect(charD.texture.frame.height).to.equal(20); - const charE = font.chars['E'.charCodeAt(0) || 69]; - - expect(charE).to.be.undefined; - done(); - }); - }); -}); - -describe('PIXI.loaders.parseBitmapFontData', function () -{ - it('should exist', function () - { - expect(parseBitmapFontData).to.be.a('function'); - }); - - // TODO: Test the parser code. -}); diff --git a/packages/loaders/test/index.js b/packages/loaders/test/index.js index f00de5f..72c6554 100644 --- a/packages/loaders/test/index.js +++ b/packages/loaders/test/index.js @@ -1,4 +1,2 @@ -require('./bitmapFontParser'); require('./loader'); -require('./spritesheetParser'); require('./textureParser'); diff --git a/packages/loaders/test/resources/atlas.json b/packages/loaders/test/resources/atlas.json deleted file mode 100644 index 86e65a5..0000000 --- a/packages/loaders/test/resources/atlas.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas.png b/packages/loaders/test/resources/atlas.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/atlas@0.5x.json b/packages/loaders/test/resources/atlas@0.5x.json deleted file mode 100644 index ae990a1..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "meta": { - "image": "atlas@0.5x.png", - "size": {"w":256,"h":256}, - "scale": "1" - }, - "frames": { - "resources/test.png": - { - "frame": {"x":2,"y":2,"w":152,"h":188}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, - "sourceSize": {"w":300,"h":225} - }, - "resources/font.png": - { - "frame": {"x":158,"y":2,"w":40,"h":42}, - "rotated": false, - "trimmed": true, - "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, - "sourceSize": {"w":43,"h":46} - } - } -} \ No newline at end of file diff --git a/packages/loaders/test/resources/atlas@0.5x.png b/packages/loaders/test/resources/atlas@0.5x.png deleted file mode 100644 index d5e7892..0000000 --- a/packages/loaders/test/resources/atlas@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font.fnt b/packages/loaders/test/resources/font.fnt deleted file mode 100644 index 56e1060..0000000 --- a/packages/loaders/test/resources/font.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font.png b/packages/loaders/test/resources/font.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/resources/font@0.5x.fnt b/packages/loaders/test/resources/font@0.5x.fnt deleted file mode 100644 index 6c247c7..0000000 --- a/packages/loaders/test/resources/font@0.5x.fnt +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/loaders/test/resources/font@0.5x.png b/packages/loaders/test/resources/font@0.5x.png deleted file mode 100644 index cf772e9..0000000 --- a/packages/loaders/test/resources/font@0.5x.png +++ /dev/null Binary files differ diff --git a/packages/loaders/test/spritesheetParser.js b/packages/loaders/test/spritesheetParser.js deleted file mode 100644 index 98890b8..0000000 --- a/packages/loaders/test/spritesheetParser.js +++ /dev/null @@ -1,213 +0,0 @@ -const path = require('path'); -const { spritesheetParser, Resource, Loader, getResourcePath } = require('../'); -const { Texture, BaseTexture } = require('@pixi/core'); - -describe('PIXI.loaders.spritesheetParser', function () -{ - it('should exist and return a function', function () - { - expect(spritesheetParser).to.be.a('function'); - expect(spritesheetParser()).to.be.a('function'); - }); - - it('should do nothing if the resource is not JSON', function () - { - const spy = sinon.spy(); - const res = {}; - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should do nothing if the resource is JSON, but improper format', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, {}); - - spritesheetParser()(res, spy); - - expect(spy).to.have.been.calledOnce; - expect(res.textures).to.be.undefined; - }); - - it('should load the image & create textures if json is properly formatted', function () - { - const spy = sinon.spy(); - const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); - const loader = new Loader(); - const addStub = sinon.stub(loader, 'add'); - const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); - - imgRes.texture = new Texture(new BaseTexture(imgRes.data)); - - addStub.yields(imgRes); - - spritesheetParser().call(loader, res, spy); - - addStub.restore(); - - expect(spy).to.have.been.calledOnce; - expect(addStub).to.have.been.calledWith( - `${res.name}_image`, - `${path.dirname(res.url)}/${res.data.meta.image}` - ); - expect(res).to.have.property('textures') - .that.is.an('object') - .with.keys(Object.keys(getJsonSpritesheet().frames)) - .and.has.property('0.png') - .that.is.an.instanceof(Texture); - }); - - it('should build the image url', function () - { - function getPath(url, image) - { - return getResourcePath({ - url, - data: { meta: { image } }, - }); - } - - let result = getPath('http://some.com/spritesheet.json', 'img.png'); - - expect(result).to.be.equals('http://some.com/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('http://some.com/some/dir/img.png'); - - result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('http://some.com/some/img.png'); - - result = getPath('/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/img.png'); - - result = getPath('/some/dir/spritesheet.json', 'img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', './img.png'); - expect(result).to.be.equals('/some/dir/img.png'); - - result = getPath('/some/dir/spritesheet.json', '../img.png'); - expect(result).to.be.equals('/some/img.png'); - }); - - // TODO: Test that rectangles are created correctly. - // TODO: Test that bathc processing works correctly. - // TODO: Test that resolution processing works correctly. - // TODO: Test that metadata is honored. -}); - -function createMockResource(type, data) -{ - const name = `${Math.floor(Date.now() * Math.random())}`; - - return { - url: `http://localhost/doesnt_exist/${name}`, - name, - type, - data, - metadata: {}, - }; -} - -function getJsonSpritesheet() -{ - /* eslint-disable */ - return {"frames": { - "0.png": - { - "frame": {"x":14,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "1.png": - { - "frame": {"x":14,"y":42,"w":12,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, - "sourceSize": {"w":12,"h":14} - }, - "2.png": - { - "frame": {"x":14,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "3.png": - { - "frame": {"x":42,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "4.png": - { - "frame": {"x":28,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "5.png": - { - "frame": {"x":14,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "6.png": - { - "frame": {"x":0,"y":42,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "7.png": - { - "frame": {"x":0,"y":28,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "8.png": - { - "frame": {"x":0,"y":14,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }, - "9.png": - { - "frame": {"x":0,"y":0,"w":14,"h":14}, - "rotated": false, - "trimmed": false, - "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, - "sourceSize": {"w":14,"h":14} - }}, - "meta": { - "app": "http://www.texturepacker.com", - "version": "1.0", - "image": "hud.png", - "format": "RGBA8888", - "size": {"w":64,"h":64}, - "scale": "1", - "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" - } - }; - /* eslint-enable */ -} diff --git a/packages/math/package.json b/packages/math/package.json index ad79dcf..9983d2c 100644 --- a/packages/math/package.json +++ b/packages/math/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,7 +31,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/math/rollup.config.js b/packages/math/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/math/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mesh/package.json b/packages/mesh/package.json index f7e3bb3..14648a0 100644 --- a/packages/mesh/package.json +++ b/packages/mesh/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -39,7 +39,6 @@ "@pixi/loaders": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mesh/rollup.config.js b/packages/mesh/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mesh/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-app-loader/LICENSE b/packages/mixin-app-loader/LICENSE new file mode 100644 index 0000000..5d16b50 --- /dev/null +++ b/packages/mixin-app-loader/LICENSE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2013-2017 Mathew Groves, Chad Engler + +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. \ No newline at end of file diff --git a/packages/mixin-app-loader/README.md b/packages/mixin-app-loader/README.md new file mode 100644 index 0000000..3e89f86 --- /dev/null +++ b/packages/mixin-app-loader/README.md @@ -0,0 +1,13 @@ +# @pixi/mixin-app-loader + +## Installation + +```bash +npm install @pixi/mixin-app-loader +``` + +## Usage + +```js +import '@pixi/mixin-app-loader'; +``` \ No newline at end of file diff --git a/packages/mixin-app-loader/package.json b/packages/mixin-app-loader/package.json new file mode 100644 index 0000000..e865cff --- /dev/null +++ b/packages/mixin-app-loader/package.json @@ -0,0 +1,41 @@ +{ + "name": "@pixi/mixin-app-loader", + "version": "5.0.0-alpha", + "main": "lib/mixin-app-loader.js", + "module": "lib/mixin-app-loader.es.js", + "description": "Support for loader in Application", + "author": "Mat Groves", + "contributors": [ + "Matt Karl " + ], + "homepage": "http://pixijs.com/", + "bugs": "https://github.com/pixijs/pixi.js/issues", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/pixijs/pixi.js.git" + }, + "publishConfig": { + "access": "public" + }, + "scripts": { + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", + "postversion": "npm run build", + "test": "tester" + }, + "files": [ + "lib" + ], + "dependencies": { + "@pixi/app": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" + }, + "devDependencies": { + "@pixi/utils": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", + "@internal/builder": "^5.0.0-alpha", + "rollup": "^0.50.0" + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/src/index.js b/packages/mixin-app-loader/src/index.js new file mode 100644 index 0000000..354997a --- /dev/null +++ b/packages/mixin-app-loader/src/index.js @@ -0,0 +1,38 @@ +import { Application } from '@pixi/app'; +import { Loader, shared } from '@pixi/loaders'; + +Application.prototype._loader = null; + +/** + * Loader instance to help with asset loading. + * @name PIXI.Application#loader + * @type {PIXI.loaders.Loader} + */ +Object.defineProperties(Application.prototype, { + loader: { + get() + { + if (!this._loader && this._options) + { + const { sharedLoader } = this._options; + + this._loader = sharedLoader ? shared : new Loader(); + } + + return this._loader; + }, + }, +}); + +// Override the destroy function +// making sure to destroy the current Loader +Application.prototype._parentDestroy = Application.prototype.destroy; +Application.prototype.destroy = function destroy(removeView) +{ + if (this._loader) + { + this._loader.destroy(); + this._loader = null; + } + this._parentDestroy(removeView); +}; diff --git a/packages/mixin-app-loader/test/.eslintrc.json b/packages/mixin-app-loader/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/mixin-app-loader/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/mixin-app-loader/test/index.js b/packages/mixin-app-loader/test/index.js new file mode 100644 index 0000000..3468fe5 --- /dev/null +++ b/packages/mixin-app-loader/test/index.js @@ -0,0 +1,35 @@ +const { Application } = require('@pixi/app'); +const { Loader, shared } = require('@pixi/loaders'); +const { skipHello } = require('@pixi/utils'); + +require('../'); + +skipHello(); + +describe('PIXI.Application#loader', function () +{ + it('should contain loader property', function () + { + const obj = new Application(); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); + + it('should use sharedLoader option', function () + { + const obj = new Application({ sharedLoader: true }); + + expect(obj.loader).to.be.not.undefined; + expect(obj.loader).to.be.instanceof(Loader); + expect(obj.loader).to.equal(shared); + + obj.destroy(); + + expect(obj.loader).to.be.null; + }); +}); diff --git a/packages/mixin-cache-as-bitmap/package.json b/packages/mixin-cache-as-bitmap/package.json index 10d64e5..146d7bd 100644 --- a/packages/mixin-cache-as-bitmap/package.json +++ b/packages/mixin-cache-as-bitmap/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-cache-as-bitmap/rollup.config.js b/packages/mixin-cache-as-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-cache-as-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-child-by-name/package.json b/packages/mixin-get-child-by-name/package.json index ff8518e..9d547d4 100644 --- a/packages/mixin-get-child-by-name/package.json +++ b/packages/mixin-get-child-by-name/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-child-by-name/rollup.config.js b/packages/mixin-get-child-by-name/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-child-by-name/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/mixin-get-global-position/package.json b/packages/mixin-get-global-position/package.json index 97f13ed..53fd326 100644 --- a/packages/mixin-get-global-position/package.json +++ b/packages/mixin-get-global-position/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -35,7 +35,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/mixin-get-global-position/rollup.config.js b/packages/mixin-get-global-position/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/mixin-get-global-position/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/particles/package.json b/packages/particles/package.json index 9fdd3a3..44a86ad 100644 --- a/packages/particles/package.json +++ b/packages/particles/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -34,11 +34,10 @@ "@pixi/utils": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "pixi-gl-core": "^1.0.3" + "pixi-gl-core": "^2.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/particles/rollup.config.js b/packages/particles/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/particles/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/polyfill/package.json b/packages/polyfill/package.json index 3e5e611..2cfddf0 100644 --- a/packages/polyfill/package.json +++ b/packages/polyfill/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -33,7 +33,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/polyfill/rollup.config.js b/packages/polyfill/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/polyfill/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/prepare/package.json b/packages/prepare/package.json index d7087d9..20c46bf 100644 --- a/packages/prepare/package.json +++ b/packages/prepare/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/prepare/rollup.config.js b/packages/prepare/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/prepare/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/settings/package.json b/packages/settings/package.json index 87d7cef..2b92913 100644 --- a/packages/settings/package.json +++ b/packages/settings/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/settings/rollup.config.js b/packages/settings/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/settings/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-animated/package.json b/packages/sprite-animated/package.json index 14eeab0..172398d 100644 --- a/packages/sprite-animated/package.json +++ b/packages/sprite-animated/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "exit 0" }, @@ -35,7 +35,6 @@ }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-animated/rollup.config.js b/packages/sprite-animated/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-animated/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite-tiling/package.json b/packages/sprite-tiling/package.json index bcbda30..368984f 100644 --- a/packages/sprite-tiling/package.json +++ b/packages/sprite-tiling/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -39,7 +39,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite-tiling/rollup.config.js b/packages/sprite-tiling/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite-tiling/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/sprite/package.json b/packages/sprite/package.json index 0d4a808..ad99ab1 100644 --- a/packages/sprite/package.json +++ b/packages/sprite/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -40,7 +40,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/sprite/rollup.config.js b/packages/sprite/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/sprite/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/package.json b/packages/spritesheet/package.json index abcd2b6..fd4ce30 100644 --- a/packages/spritesheet/package.json +++ b/packages/spritesheet/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -31,12 +31,12 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", - "@pixi/utils": "^5.0.0-alpha" + "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha" }, "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/spritesheet/rollup.config.js b/packages/spritesheet/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/spritesheet/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/spritesheet/src/SpritesheetLoader.js b/packages/spritesheet/src/SpritesheetLoader.js new file mode 100644 index 0000000..c7b34ea --- /dev/null +++ b/packages/spritesheet/src/SpritesheetLoader.js @@ -0,0 +1,83 @@ +import url from 'url'; +import { Resource, Loader } from '@pixi/loaders'; +import Spritesheet from './Spritesheet'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * texture atlases that have been created with TexturePacker or + * similar JSON-based spritesheet. This automatically generates + * Texture resources. + * @class + * @memberof PIXI + */ +export default class SpritesheetLoader +{ + /** + * Middleware function to support Spritesheets, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function spritesheetLoader(resource, next) + { + const imageResourceName = `${resource.name}_image`; + + // skip if no data, its not json, it isn't spritesheet data, or the image resource already exists + if (!resource.data + || resource.type !== Resource.TYPE.JSON + || !resource.data.frames + || this.resources[imageResourceName] + ) + { + next(); + + return; + } + + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + const resourcePath = SpritesheetLoader.getResourcePath(resource, this.baseUrl); + + // load the image for this sheet + this.add(imageResourceName, resourcePath, loadOptions, function onImageLoad(res) + { + const spritesheet = new Spritesheet( + res.texture.baseTexture, + resource.data, + resource.url + ); + + spritesheet.parse(() => + { + resource.spritesheet = spritesheet; + resource.textures = spritesheet.textures; + next(); + }); + }); + }; + } + + /** + * Get the spritesheets root path + * @param {PIXI.loader.Resource} resource - Resource to check path + * @param {string} baseUrl - Base root url + */ + static getResourcePath(resource, baseUrl) + { + // Prepend url path unless the resource image is a data url + if (resource.isDataUrl) + { + return resource.data.meta.image; + } + + return url.resolve(resource.url.replace(baseUrl, ''), resource.data.meta.image); + } +} + +// Install loader support for Spritesheet objects +Loader.useMiddleware(SpritesheetLoader.middleware); diff --git a/packages/spritesheet/src/index.js b/packages/spritesheet/src/index.js index 51d96a1..b9ee1e8 100644 --- a/packages/spritesheet/src/index.js +++ b/packages/spritesheet/src/index.js @@ -1 +1,2 @@ export { default as Spritesheet } from './Spritesheet'; +export { default as SpritesheetLoader } from './SpritesheetLoader'; diff --git a/packages/spritesheet/test/Spritesheet.js b/packages/spritesheet/test/Spritesheet.js new file mode 100644 index 0000000..35d8688 --- /dev/null +++ b/packages/spritesheet/test/Spritesheet.js @@ -0,0 +1,105 @@ +const { Spritesheet } = require('../'); +const { BaseTexture, Texture } = require('@pixi/core'); +const path = require('path'); + +describe('PIXI.Spritesheet', function () +{ + before(function () + { + this.resources = path.join(__dirname, 'resources'); + this.validate = function (spritesheet, done) + { + spritesheet.parse(function (textures) + { + const id = 'goldmine_10_5.png'; + const width = Math.floor(spritesheet.data.frames[id].frame.w); + const height = Math.floor(spritesheet.data.frames[id].frame.h); + + expect(Object.keys(textures).length).to.equal(1); + expect(Object.keys(spritesheet.textures).length).to.equal(1); + expect(textures[id]).to.be.an.instanceof(Texture); + expect(textures[id].width).to.equal(width / spritesheet.resolution); + expect(textures[id].height).to.equal(height / spritesheet.resolution); + expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); + spritesheet.destroy(true); + expect(spritesheet.textures).to.be.null; + expect(spritesheet.baseTexture).to.be.null; + done(); + }); + }; + }); + + it('should exist on PIXI', function () + { + expect(Spritesheet).to.be.a.function; + expect(Spritesheet.BATCH_SIZE).to.be.a.number; + }); + + it('should create an instance', function () + { + const baseTexture = new BaseTexture(); + const data = { + frames: {}, + meta: {}, + }; + + const spritesheet = new Spritesheet(baseTexture, data); + + expect(spritesheet.data).to.equal(data); + expect(spritesheet.baseTexture).to.equal(baseTexture); + expect(spritesheet.resolution).to.equal(1); + + spritesheet.destroy(true); + }); + + it('should create instance with scale resolution', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + this.validate(spritesheet, done); + }; + }); + + it('should create instance with BaseTexture source scale', function (done) + { + const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require + const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); + const spritesheet = new Spritesheet(baseTexture, data); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1.png'); + expect(spritesheet.resolution).to.equal(0.5); + + this.validate(spritesheet, done); + }); + + it('should create instance with filename resolution', function (done) + { + const uri = path.resolve(this.resources, 'building1@2x.json'); + const data = require(uri); // eslint-disable-line global-require + const image = new Image(); + + image.src = path.join(this.resources, data.meta.image); + image.onload = () => + { + const baseTexture = new BaseTexture(image, null, 1); + const spritesheet = new Spritesheet(baseTexture, data, uri); + + expect(data).to.be.an.object; + expect(data.meta.image).to.equal('building1@2x.png'); + expect(spritesheet.resolution).to.equal(2); + + this.validate(spritesheet, done); + }; + }); +}); diff --git a/packages/spritesheet/test/SpritesheetLoader.js b/packages/spritesheet/test/SpritesheetLoader.js new file mode 100644 index 0000000..e4205ec --- /dev/null +++ b/packages/spritesheet/test/SpritesheetLoader.js @@ -0,0 +1,214 @@ +const path = require('path'); +const { Loader, Resource } = require('@pixi/loaders'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { SpritesheetLoader } = require('../'); + +describe('PIXI.SpritesheetLoader', function () +{ + it('should exist and return a function', function () + { + expect(SpritesheetLoader.middleware).to.be.a('function'); + expect(SpritesheetLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not JSON', function () + { + const spy = sinon.spy(); + const res = {}; + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is JSON, but improper format', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, {}); + + SpritesheetLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should load the image & create textures if json is properly formatted', function () + { + const spy = sinon.spy(); + const res = createMockResource(Resource.TYPE.JSON, getJsonSpritesheet()); + const loader = new Loader(); + const addStub = sinon.stub(loader, 'add'); + const imgRes = createMockResource(Resource.TYPE.IMAGE, new Image()); + + imgRes.texture = new Texture(new BaseTexture(imgRes.data)); + + addStub.yields(imgRes); + + SpritesheetLoader.middleware().call(loader, res, spy); + + addStub.restore(); + + expect(spy).to.have.been.calledOnce; + expect(addStub).to.have.been.calledWith( + `${res.name}_image`, + `${path.dirname(res.url)}/${res.data.meta.image}` + ); + expect(res).to.have.property('textures') + .that.is.an('object') + .with.keys(Object.keys(getJsonSpritesheet().frames)) + .and.has.property('0.png') + .that.is.an.instanceof(Texture); + }); + + it('should build the image url', function () + { + function getPath(url, image) + { + return SpritesheetLoader.getResourcePath({ + url, + data: { meta: { image } }, + }); + } + + let result = getPath('http://some.com/spritesheet.json', 'img.png'); + + expect(result).to.be.equals('http://some.com/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('http://some.com/some/dir/img.png'); + + result = getPath('http://some.com/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('http://some.com/some/img.png'); + + result = getPath('/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/img.png'); + + result = getPath('/some/dir/spritesheet.json', 'img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', './img.png'); + expect(result).to.be.equals('/some/dir/img.png'); + + result = getPath('/some/dir/spritesheet.json', '../img.png'); + expect(result).to.be.equals('/some/img.png'); + }); + + // TODO: Test that rectangles are created correctly. + // TODO: Test that bathc processing works correctly. + // TODO: Test that resolution processing works correctly. + // TODO: Test that metadata is honored. +}); + +function createMockResource(type, data) +{ + const name = `${Math.floor(Date.now() * Math.random())}`; + + return { + url: `http://localhost/doesnt_exist/${name}`, + name, + type, + data, + metadata: {}, + }; +} + +function getJsonSpritesheet() +{ + /* eslint-disable */ + return {"frames": { + "0.png": + { + "frame": {"x":14,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "1.png": + { + "frame": {"x":14,"y":42,"w":12,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":12,"h":14}, + "sourceSize": {"w":12,"h":14} + }, + "2.png": + { + "frame": {"x":14,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "3.png": + { + "frame": {"x":42,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "4.png": + { + "frame": {"x":28,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "5.png": + { + "frame": {"x":14,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "6.png": + { + "frame": {"x":0,"y":42,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "7.png": + { + "frame": {"x":0,"y":28,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "8.png": + { + "frame": {"x":0,"y":14,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }, + "9.png": + { + "frame": {"x":0,"y":0,"w":14,"h":14}, + "rotated": false, + "trimmed": false, + "spriteSourceSize": {"x":0,"y":0,"w":14,"h":14}, + "sourceSize": {"w":14,"h":14} + }}, + "meta": { + "app": "http://www.texturepacker.com", + "version": "1.0", + "image": "hud.png", + "format": "RGBA8888", + "size": {"w":64,"h":64}, + "scale": "1", + "smartupdate": "$TexturePacker:SmartUpdate:47025c98c8b10634b75172d4ed7e7edc$" + } + }; + /* eslint-enable */ +} diff --git a/packages/spritesheet/test/index.js b/packages/spritesheet/test/index.js index 35d8688..8cf5636 100644 --- a/packages/spritesheet/test/index.js +++ b/packages/spritesheet/test/index.js @@ -1,105 +1,2 @@ -const { Spritesheet } = require('../'); -const { BaseTexture, Texture } = require('@pixi/core'); -const path = require('path'); - -describe('PIXI.Spritesheet', function () -{ - before(function () - { - this.resources = path.join(__dirname, 'resources'); - this.validate = function (spritesheet, done) - { - spritesheet.parse(function (textures) - { - const id = 'goldmine_10_5.png'; - const width = Math.floor(spritesheet.data.frames[id].frame.w); - const height = Math.floor(spritesheet.data.frames[id].frame.h); - - expect(Object.keys(textures).length).to.equal(1); - expect(Object.keys(spritesheet.textures).length).to.equal(1); - expect(textures[id]).to.be.an.instanceof(Texture); - expect(textures[id].width).to.equal(width / spritesheet.resolution); - expect(textures[id].height).to.equal(height / spritesheet.resolution); - expect(textures[id].textureCacheIds.indexOf(id)).to.equal(0); - spritesheet.destroy(true); - expect(spritesheet.textures).to.be.null; - expect(spritesheet.baseTexture).to.be.null; - done(); - }); - }; - }); - - it('should exist on PIXI', function () - { - expect(Spritesheet).to.be.a.function; - expect(Spritesheet.BATCH_SIZE).to.be.a.number; - }); - - it('should create an instance', function () - { - const baseTexture = new BaseTexture(); - const data = { - frames: {}, - meta: {}, - }; - - const spritesheet = new Spritesheet(baseTexture, data); - - expect(spritesheet.data).to.equal(data); - expect(spritesheet.baseTexture).to.equal(baseTexture); - expect(spritesheet.resolution).to.equal(1); - - spritesheet.destroy(true); - }); - - it('should create instance with scale resolution', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - this.validate(spritesheet, done); - }; - }); - - it('should create instance with BaseTexture source scale', function (done) - { - const data = require(path.resolve(this.resources, 'building1.json')); // eslint-disable-line global-require - const baseTexture = new BaseTexture.fromImage(data.meta.image, undefined, undefined, 1.5); - const spritesheet = new Spritesheet(baseTexture, data); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1.png'); - expect(spritesheet.resolution).to.equal(0.5); - - this.validate(spritesheet, done); - }); - - it('should create instance with filename resolution', function (done) - { - const uri = path.resolve(this.resources, 'building1@2x.json'); - const data = require(uri); // eslint-disable-line global-require - const image = new Image(); - - image.src = path.join(this.resources, data.meta.image); - image.onload = () => - { - const baseTexture = new BaseTexture(image, null, 1); - const spritesheet = new Spritesheet(baseTexture, data, uri); - - expect(data).to.be.an.object; - expect(data.meta.image).to.equal('building1@2x.png'); - expect(spritesheet.resolution).to.equal(2); - - this.validate(spritesheet, done); - }; - }); -}); +require('./Spritesheet'); +require('./SpritesheetLoader'); diff --git a/packages/text-bitmap/package.json b/packages/text-bitmap/package.json index ba9ae2b..840b01a 100644 --- a/packages/text-bitmap/package.json +++ b/packages/text-bitmap/package.json @@ -19,11 +19,11 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", - "test": "exit 0" + "test": "tester" }, "files": [ "lib" @@ -31,14 +31,16 @@ "dependencies": { "@pixi/core": "^5.0.0-alpha", "@pixi/utils": "^5.0.0-alpha", + "@pixi/loaders": "^5.0.0-alpha", "@pixi/sprite": "^5.0.0-alpha", "@pixi/settings": "^5.0.0-alpha", "@pixi/math": "^5.0.0-alpha", "@pixi/display": "^5.0.0-alpha" }, "devDependencies": { + "@pixi/spritesheet": "^5.0.0-alpha", + "@internal/tester": "^5.0.0-alpha", "@internal/builder": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text-bitmap/rollup.config.js b/packages/text-bitmap/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text-bitmap/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text-bitmap/src/BitmapFontLoader.js b/packages/text-bitmap/src/BitmapFontLoader.js new file mode 100644 index 0000000..3956060 --- /dev/null +++ b/packages/text-bitmap/src/BitmapFontLoader.js @@ -0,0 +1,112 @@ +import * as path from 'path'; +import { TextureCache } from '@pixi/utils'; +import { Resource, Loader } from '@pixi/loaders'; +import BitmapText from './BitmapText'; + +/** + * {@link PIXI.loaders.Loader Loader} middleware for loading + * bitmap-based fonts suitable for using with {@link PIXI.BitmapText}. + * @class + * @memberof PIXI + */ +export default class BitmapFontLoader +{ + /** + * Register a BitmapText font from loader resource. + * + * @param {PIXI.loaders.Resource} resource - Loader resource. + * @param {PIXI.Texture} texture - Reference to texture. + */ + static parse(resource, texture) + { + resource.bitmapFont = BitmapText.registerFont(resource.data, texture); + } + + /** + * Middleware function to support BitmapText fonts, this is automatically installed. + * @see PIXI.loaders.Loader.useMiddleware + */ + static middleware() + { + return function bitmapFontLoader(resource, next) + { + // skip if no data or not xml data + if (!resource.data || resource.type !== Resource.TYPE.XML) + { + next(); + + return; + } + + // skip if not bitmap font data, using some silly duck-typing + if (resource.data.getElementsByTagName('page').length === 0 + || resource.data.getElementsByTagName('info').length === 0 + || resource.data.getElementsByTagName('info')[0].getAttribute('face') === null + ) + { + next(); + + return; + } + + let xmlUrl = !resource.isDataUrl ? path.dirname(resource.url) : ''; + + if (resource.isDataUrl) + { + if (xmlUrl === '.') + { + xmlUrl = ''; + } + + if (this.baseUrl && xmlUrl) + { + // if baseurl has a trailing slash then add one to xmlUrl so the replace works below + if (this.baseUrl.charAt(this.baseUrl.length - 1) === '/') + { + xmlUrl += '/'; + } + } + } + + // remove baseUrl from xmlUrl + xmlUrl = xmlUrl.replace(this.baseUrl, ''); + + // if there is an xmlUrl now, it needs a trailing slash. Ensure that it does if the string isn't empty. + if (xmlUrl && xmlUrl.charAt(xmlUrl.length - 1) !== '/') + { + xmlUrl += '/'; + } + + const textureUrl = xmlUrl + resource.data.getElementsByTagName('page')[0].getAttribute('file'); + + if (TextureCache[textureUrl]) + { + // reuse existing texture + BitmapFontLoader.parse(resource, TextureCache[textureUrl]); + next(); + } + else + { + const loadOptions = { + crossOrigin: resource.crossOrigin, + loadType: Resource.LOAD_TYPE.IMAGE, + metadata: resource.metadata.imageMetadata, + parentResource: resource, + }; + + // load the texture for the font + this.add(`${resource.name}_image`, textureUrl, loadOptions, (res) => + { + BitmapFontLoader.parse(resource, res.texture); + next(); + }); + } + }; + } +} + +// Add custom add support for loading fnt files as XML +Resource.setExtensionXhrType('fnt', Resource.XHR_RESPONSE_TYPE.DOCUMENT); + +// Install loader support for BitmapText +Loader.useMiddleware(BitmapFontLoader.middleware); diff --git a/packages/text-bitmap/src/index.js b/packages/text-bitmap/src/index.js index a98e7b4..e5afd2c 100644 --- a/packages/text-bitmap/src/index.js +++ b/packages/text-bitmap/src/index.js @@ -1 +1,2 @@ export { default as BitmapText } from './BitmapText'; +export { default as BitmapFontLoader } from './BitmapFontLoader'; diff --git a/packages/text-bitmap/test/.eslintrc.json b/packages/text-bitmap/test/.eslintrc.json new file mode 100644 index 0000000..2094b04 --- /dev/null +++ b/packages/text-bitmap/test/.eslintrc.json @@ -0,0 +1,12 @@ +{ + "globals": { + "expect": false, + "assert": false, + "sinon": false, + "PIXI": false + }, + "rules": { + "func-names": 0, + "no-unused-expressions": 0 + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/BitmapFontLoader.js b/packages/text-bitmap/test/BitmapFontLoader.js new file mode 100644 index 0000000..a76fc1c --- /dev/null +++ b/packages/text-bitmap/test/BitmapFontLoader.js @@ -0,0 +1,319 @@ +const path = require('path'); +const fs = require('fs'); +const { BaseTextureCache, TextureCache } = require('@pixi/utils'); +const { Texture, BaseTexture } = require('@pixi/core'); +const { Spritesheet } = require('@pixi/spritesheet'); +const { BitmapText, BitmapFontLoader } = require('../'); + +describe('PIXI.BitmapFontLoader', function () +{ + afterEach(function () + { + for (const font in BitmapText.fonts) + { + delete BitmapText.fonts[font]; + } + for (const baseTexture in BaseTextureCache) + { + delete BaseTextureCache[baseTexture]; + } + for (const texture in TextureCache) + { + delete TextureCache[texture]; + } + }); + + before(function (done) + { + const resolveURL = (url) => path.resolve(this.resources, url); + + this.resources = path.join(__dirname, 'resources'); + this.fontXML = null; + this.fontScaledXML = null; + this.fontImage = null; + this.fontScaledImage = null; + this.atlasImage = null; + this.atlasScaledImage = null; + this.atlasJSON = require(resolveURL('atlas.json')); // eslint-disable-line global-require + this.atlasScaledJSON = require(resolveURL('atlas@0.5x.json')); // eslint-disable-line global-require + + const loadXML = (url) => new Promise((resolve) => + fs.readFile(resolveURL(url), 'utf8', (err, data) => + { + expect(err).to.be.null; + resolve((new window.DOMParser()).parseFromString(data, 'text/xml')); + })); + + const loadImage = (url) => new Promise((resolve) => + { + const image = new Image(); + + image.onload = () => resolve(image); + image.src = resolveURL(url); + }); + + Promise.all([ + loadXML('font.fnt'), + loadXML('font@0.5x.fnt'), + loadImage('font.png'), + loadImage('font@0.5x.png'), + loadImage('atlas.png'), + loadImage('atlas@0.5x.png'), + ]).then(([ + fontXML, + fontScaledXML, + fontImage, + fontScaledImage, + atlasImage, + atlasScaledImage, + ]) => + { + this.fontXML = fontXML; + this.fontScaledXML = fontScaledXML; + this.fontImage = fontImage; + this.fontScaledImage = fontScaledImage; + this.atlasImage = atlasImage; + this.atlasScaledImage = atlasScaledImage; + done(); + }); + }); + + it('should exist and return a function', function () + { + expect(BitmapFontLoader.middleware).to.be.a('function'); + expect(BitmapFontLoader.middleware()).to.be.a('function'); + }); + + it('should do nothing if the resource is not XML', function () + { + const spy = sinon.spy(); + const res = {}; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + it('should do nothing if the resource is not properly formatted XML', function () + { + const spy = sinon.spy(); + const res = { data: document.createDocumentFragment() }; + + BitmapFontLoader.middleware()(res, spy); + + expect(spy).to.have.been.calledOnce; + expect(res.textures).to.be.undefined; + }); + + // TODO: Test the texture cache code path. + // TODO: Test the loading texture code path. + // TODO: Test data-url code paths. + + it('should properly register bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontImage, null, 1)); + const font = BitmapText.registerFont(this.fontXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charA.texture.frame.x).to.equal(2); + expect(charA.texture.frame.y).to.equal(2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charB.texture.frame.x).to.equal(2); + expect(charB.texture.frame.y).to.equal(24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charC.texture.frame.x).to.equal(23); + expect(charC.texture.frame.y).to.equal(2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontImage); + expect(charD.texture.frame.x).to.equal(19); + expect(charD.texture.frame.y).to.equal(24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register SCALED bitmap font', function (done) + { + const texture = new Texture(new BaseTexture(this.fontScaledImage, null, 0.5)); + const font = BitmapText.registerFont(this.fontScaledXML, texture); + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charA.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charA.texture.frame.width).to.equal(38); // 19 / 0.5 + expect(charA.texture.frame.height).to.equal(40); // 20 / 0.5 + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charB.texture.frame.x).to.equal(4); // 2 / 0.5 + expect(charB.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charB.texture.frame.width).to.equal(30); // 15 / 0.5 + expect(charB.texture.frame.height).to.equal(40); // 20 / 0.5 + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charC.texture.frame.x).to.equal(46); // 23 / 0.5 + expect(charC.texture.frame.y).to.equal(4); // 2 / 0.5 + expect(charC.texture.frame.width).to.equal(36); // 18 / 0.5 + expect(charC.texture.frame.height).to.equal(40); // 20 / 0.5 + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.fontScaledImage); + expect(charD.texture.frame.x).to.equal(38); // 19 / 0.5 + expect(charD.texture.frame.y).to.equal(48); // 24 / 0.5 + expect(charD.texture.frame.width).to.equal(34); // 17 / 0.5 + expect(charD.texture.frame.height).to.equal(40); // 20 / 0.5 + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + + it('should properly register bitmap font NESTED into spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasJSON); + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should properly register bitmap font NESTED into SCALED spritesheet', function (done) + { + const baseTexture = new BaseTexture(this.atlasScaledImage, null, 1); + const spritesheet = new Spritesheet(baseTexture, this.atlasScaledJSON); + + spritesheet.resolution = 1; + + spritesheet.parse(() => + { + const fontTexture = Texture.fromFrame('resources/font.png'); + const font = BitmapText.registerFont(this.fontXML, fontTexture); + const fontX = 158; // bare value from spritesheet frame + const fontY = 2; // bare value from spritesheet frame + + expect(font).to.be.an.object; + expect(BitmapText.fonts.font).to.equal(font); + expect(font).to.have.property('chars'); + const charA = font.chars['A'.charCodeAt(0) || 65]; + + expect(charA).to.exist; + expect(charA.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charA.texture.frame.x).to.equal(fontX + 2); + expect(charA.texture.frame.y).to.equal(fontY + 2); + expect(charA.texture.frame.width).to.equal(19); + expect(charA.texture.frame.height).to.equal(20); + const charB = font.chars['B'.charCodeAt(0) || 66]; + + expect(charB).to.exist; + expect(charB.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charB.texture.frame.x).to.equal(fontX + 2); + expect(charB.texture.frame.y).to.equal(fontY + 24); + expect(charB.texture.frame.width).to.equal(15); + expect(charB.texture.frame.height).to.equal(20); + const charC = font.chars['C'.charCodeAt(0) || 67]; + + expect(charC).to.exist; + expect(charC.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charC.texture.frame.x).to.equal(fontX + 23); + expect(charC.texture.frame.y).to.equal(fontY + 2); + expect(charC.texture.frame.width).to.equal(18); + expect(charC.texture.frame.height).to.equal(20); + const charD = font.chars['D'.charCodeAt(0) || 68]; + + expect(charD).to.exist; + expect(charD.texture.baseTexture.resource.source).to.equal(this.atlasScaledImage); + expect(charD.texture.frame.x).to.equal(fontX + 19); + expect(charD.texture.frame.y).to.equal(fontY + 24); + expect(charD.texture.frame.width).to.equal(17); + expect(charD.texture.frame.height).to.equal(20); + const charE = font.chars['E'.charCodeAt(0) || 69]; + + expect(charE).to.be.undefined; + done(); + }); + }); + + it('should parse exist', function () + { + expect(BitmapFontLoader.parse).to.be.a('function'); + }); +}); diff --git a/packages/text-bitmap/test/index.js b/packages/text-bitmap/test/index.js new file mode 100644 index 0000000..688fee2 --- /dev/null +++ b/packages/text-bitmap/test/index.js @@ -0,0 +1 @@ +require('./BitmapFontLoader'); diff --git a/packages/text-bitmap/test/resources/atlas.json b/packages/text-bitmap/test/resources/atlas.json new file mode 100644 index 0000000..86e65a5 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas.png b/packages/text-bitmap/test/resources/atlas.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas.png Binary files differ diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.json b/packages/text-bitmap/test/resources/atlas@0.5x.json new file mode 100644 index 0000000..ae990a1 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.json @@ -0,0 +1,25 @@ +{ + "meta": { + "image": "atlas@0.5x.png", + "size": {"w":256,"h":256}, + "scale": "1" + }, + "frames": { + "resources/test.png": + { + "frame": {"x":2,"y":2,"w":152,"h":188}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":74,"y":36,"w":152,"h":188}, + "sourceSize": {"w":300,"h":225} + }, + "resources/font.png": + { + "frame": {"x":158,"y":2,"w":40,"h":42}, + "rotated": false, + "trimmed": true, + "spriteSourceSize": {"x":2,"y":2,"w":40,"h":42}, + "sourceSize": {"w":43,"h":46} + } + } +} \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/atlas@0.5x.png b/packages/text-bitmap/test/resources/atlas@0.5x.png new file mode 100644 index 0000000..d5e7892 --- /dev/null +++ b/packages/text-bitmap/test/resources/atlas@0.5x.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font.fnt b/packages/text-bitmap/test/resources/font.fnt new file mode 100644 index 0000000..56e1060 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font.png b/packages/text-bitmap/test/resources/font.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font.png Binary files differ diff --git a/packages/text-bitmap/test/resources/font@0.5x.fnt b/packages/text-bitmap/test/resources/font@0.5x.fnt new file mode 100644 index 0000000..6c247c7 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.fnt @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/text-bitmap/test/resources/font@0.5x.png b/packages/text-bitmap/test/resources/font@0.5x.png new file mode 100644 index 0000000..cf772e9 --- /dev/null +++ b/packages/text-bitmap/test/resources/font@0.5x.png Binary files differ diff --git a/packages/text/package.json b/packages/text/package.json index 294eb74..cd82dc9 100644 --- a/packages/text/package.json +++ b/packages/text/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/text/rollup.config.js b/packages/text/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/text/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/text/src/TextStyle.js b/packages/text/src/TextStyle.js index 39bdbb9..de85633 100644 --- a/packages/text/src/TextStyle.js +++ b/packages/text/src/TextStyle.js @@ -75,7 +75,8 @@ * @param {number} [style.letterSpacing=0] - The amount of spacing between letters, default is 0 * @param {number} [style.lineHeight] - The line height, a number that represents the vertical space that a letter uses * @param {string} [style.lineJoin='miter'] - The lineJoin property sets the type of corner created, it can resolve - * spiked text issues. Default is 'miter' (creates a sharp corner). + * spiked text issues. Possible values "miter" (creates a sharp corner), "round" (creates a round corner) or "bevel" + * (creates a squared corner). * @param {number} [style.miterLimit=10] - The miter limit to use when using the 'miter' lineJoin mode. This can reduce * or increase the spikiness of rendered text. * @param {number} [style.padding=0] - Occasionally some fonts are cropped. Adding some padding will prevent this from diff --git a/packages/ticker/package.json b/packages/ticker/package.json index aa9e44c..1ef181d 100644 --- a/packages/ticker/package.json +++ b/packages/ticker/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -34,7 +34,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/ticker/rollup.config.js b/packages/ticker/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/ticker/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/package.json b/packages/utils/package.json index e1b9c47..772e7bc 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -19,9 +19,9 @@ "access": "public" }, "scripts": { - "build:dev": "rollup -c && rollup -c -f cjs", - "build": "rollup -cp && rollup -cp -f cjs", - "watch": "rollup -cw", + "build:dev": "rollup -c node_modules/.bin/config", + "build": "rollup -p -c node_modules/.bin/config", + "watch": "rollup -w -c node_modules/.bin/config", "postversion": "npm run build", "test": "tester" }, @@ -38,7 +38,6 @@ "devDependencies": { "@internal/builder": "^5.0.0-alpha", "@internal/tester": "^5.0.0-alpha", - "rollup": "^0.50.0", - "rollup-watch": "^4.3.1" + "rollup": "^0.50.0" } } \ No newline at end of file diff --git a/packages/utils/rollup.config.js b/packages/utils/rollup.config.js deleted file mode 100644 index 15f56df..0000000 --- a/packages/utils/rollup.config.js +++ /dev/null @@ -1 +0,0 @@ -export * from '@internal/builder'; diff --git a/packages/utils/src/browser/deprecationWarn.js b/packages/utils/src/browser/deprecationWarn.js deleted file mode 100644 index 8e348da..0000000 --- a/packages/utils/src/browser/deprecationWarn.js +++ /dev/null @@ -1,37 +0,0 @@ -// provide method to give a stack track for warnings -// useful for tracking-down where deprecated methods/properties/classes -// are being used within the code -export function deprecationWarn(msg) -{ - /* eslint-disable no-console */ - let stack = new Error().stack; - - // Handle IE < 10 and Safari < 6 - if (typeof stack === 'undefined') - { - console.warn('Deprecation Warning: ', msg); - } - else - { - // chop off the stack trace which includes pixi.js internal calls - stack = stack.split('\n').splice(3).join('\n'); - - if (console.groupCollapsed) - { - console.groupCollapsed( - '%cDeprecation Warning: %c%s', - 'color:#614108;background:#fffbe6', - 'font-weight:normal;color:#614108;background:#fffbe6', - msg - ); - console.warn(stack); - console.groupEnd(); - } - else - { - console.warn('Deprecation Warning: ', msg); - console.warn(stack); - } - } - /* eslint-enable no-console */ -} diff --git a/packages/utils/src/browser/getTestContext.js b/packages/utils/src/browser/getTestContext.js deleted file mode 100644 index bd1e189..0000000 --- a/packages/utils/src/browser/getTestContext.js +++ /dev/null @@ -1,48 +0,0 @@ -import { settings } from '@pixi/settings'; - -let context = null; - -/** - * returns a little webGL context to use for program inspection. - * - * @static - * @private - * @returns {webGL-context} a gl context to test with - */ -export function getTestContext() -{ - if (!context) - { - const canvas = document.createElement('canvas'); - - let gl; - - if (settings.PREFER_WEBGL_2) - { - gl = canvas.getContext('webgl2', {}); - } - - if (!gl) - { - gl = canvas.getContext('webgl', {}) - || canvas.getContext('experimental-webgl', {}); - - if (!gl) - { - // fail, not able to get a context - throw new Error('This browser does not support webGL. Try using the canvas renderer'); - } - else - { - // for shader testing.. - gl.getExtension('WEBGL_draw_buffers'); - } - } - - context = gl; - - return gl; - } - - return context; -} diff --git a/packages/utils/src/browser/index.js b/packages/utils/src/browser/index.js index c99230d..c3fdce7 100644 --- a/packages/utils/src/browser/index.js +++ b/packages/utils/src/browser/index.js @@ -1,4 +1,2 @@ -export * from './getTestContext'; export * from './hello'; export * from './isWebGLSupported'; -export * from './deprecationWarn'; diff --git a/packages/utils/src/const.js b/packages/utils/src/const.js index 30ead03..c66c82d 100644 --- a/packages/utils/src/const.js +++ b/packages/utils/src/const.js @@ -1,15 +1,4 @@ /** - * Regexp for image type by extension. - * - * @static - * @constant - * @memberof PIXI - * @type {RegExp|string} - * @example `image.png` - */ -export const URL_FILE_EXTENSION = /\.(\w{3,4})(?:$|\?|#)/i; - -/** * Regexp for data URI. * Based on: {@link https://github.com/ragingwind/data-uri-regex} * @@ -21,15 +10,3 @@ * @example data:image/png;base64 */ export const DATA_URI = /^\s*data:(?:([\w-]+)\/([\w+.-]+))?(?:;(charset=[\w-]+|base64))?,(.*)/i; - -/** - * Regexp for SVG size. - * - * @static - * @constant - * @name SVG_SIZE - * @memberof PIXI - * @type {RegExp|string} - * @example <svg width="100" height="100"></svg> - */ -export const SVG_SIZE = /]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i; // eslint-disable-line max-len diff --git a/packages/utils/src/data/index.js b/packages/utils/src/data/index.js index 23b6cd0..294a9d5 100644 --- a/packages/utils/src/data/index.js +++ b/packages/utils/src/data/index.js @@ -1,5 +1,3 @@ export * from './createIndicesForQuads'; -export * from './getBufferType'; -export * from './interleaveTypedArrays'; export * from './uid'; export * from './sign'; diff --git a/packages/utils/src/index.js b/packages/utils/src/index.js index dd1f441..2466fa7 100644 --- a/packages/utils/src/index.js +++ b/packages/utils/src/index.js @@ -47,13 +47,17 @@ import EventEmitter from 'eventemitter3'; export { EventEmitter }; +/** + * @namespace PIXI.utils.mixins + */ +import * as mixins from './mixins'; +export { mixins }; + export * from './browser'; export * from './color'; export * from './data'; export * from './media'; export * from './network'; -export * from './plugin'; - export * from './const'; import './settings'; diff --git a/packages/utils/src/media/getSvgSize.js b/packages/utils/src/media/getSvgSize.js deleted file mode 100644 index d14b12c..0000000 --- a/packages/utils/src/media/getSvgSize.js +++ /dev/null @@ -1,31 +0,0 @@ -import { SVG_SIZE } from '../const'; - -/** - * Typedef for Size object. - * - * @typedef {object} Size - * @property {width} Width component - * @property {height} Height component - */ - -/** - * Get size from an svg string using regexp. - * - * @memberof PIXI.utils - * @function getSvgSize - * @param {string} svgString - a serialized svg element - * @return {Size|undefined} image extension - */ -export function getSvgSize(svgString) -{ - const sizeMatch = SVG_SIZE.exec(svgString); - const size = {}; - - if (sizeMatch) - { - size[sizeMatch[1]] = Math.round(parseFloat(sizeMatch[3])); - size[sizeMatch[5]] = Math.round(parseFloat(sizeMatch[7])); - } - - return size; -} diff --git a/packages/utils/src/media/index.js b/packages/utils/src/media/index.js index 7c0effe..5c8ce71 100644 --- a/packages/utils/src/media/index.js +++ b/packages/utils/src/media/index.js @@ -1,3 +1,2 @@ export * from './caches'; -export * from './getSvgSize'; export * from './trimCanvas'; diff --git a/packages/utils/src/mixins.js b/packages/utils/src/mixins.js new file mode 100644 index 0000000..335c54f --- /dev/null +++ b/packages/utils/src/mixins.js @@ -0,0 +1,57 @@ +/** + * Mixes all enumerable properties and methods from a source object to a target object. + * + * @memberof PIXI.utils.mixins + * @function mixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function mixin(target, source) +{ + if (!target || !source) return; + // in ES8/ES2017, this would be really easy: + // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + + // get all the enumerable property keys + const keys = Object.keys(source); + + // loop through properties + for (let i = 0; i < keys.length; ++i) + { + const propertyName = keys[i]; + + // Set the property using the property descriptor - this works for accessors and normal value properties + Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); + } +} + +const mixins = []; + +/** + * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation + * can take effect. + * + * @memberof PIXI.utils.mixins + * @function delayMixin + * @param {object} target The prototype or instance that properties and methods should be added to. + * @param {object} source The source of properties and methods to mix in. + */ +export function delayMixin(target, source) +{ + mixins.push(target, source); +} + +/** + * Handles all mixins queued via delayMixin(). + * + * @memberof PIXI.utils.mixins + * @function performMixins + */ +export function performMixins() +{ + for (let i = 0; i < mixins.length; i += 2) + { + mixin(mixins[i], mixins[i + 1]); + } + mixins.length = 0; +} diff --git a/packages/utils/src/network/getUrlFileExtension.js b/packages/utils/src/network/getUrlFileExtension.js deleted file mode 100644 index 407f689..0000000 --- a/packages/utils/src/network/getUrlFileExtension.js +++ /dev/null @@ -1,21 +0,0 @@ -import { URL_FILE_EXTENSION } from '../const'; - -/** - * Get type of the image by regexp for extension. Returns undefined for unknown extensions. - * - * @memberof PIXI.utils - * @function getUrlFileExtension - * @param {string} url - the image path - * @return {string|undefined} image extension - */ -export function getUrlFileExtension(url) -{ - const extension = URL_FILE_EXTENSION.exec(url); - - if (extension) - { - return extension[1].toLowerCase(); - } - - return undefined; -} diff --git a/packages/utils/src/network/index.js b/packages/utils/src/network/index.js index 3bb2549..f2f5430 100644 --- a/packages/utils/src/network/index.js +++ b/packages/utils/src/network/index.js @@ -1,4 +1,3 @@ export * from './decomposeDataUri'; export * from './determineCrossOrigin'; export * from './getResolutionOfUrl'; -export * from './getUrlFileExtension'; diff --git a/packages/utils/src/plugin/index.js b/packages/utils/src/plugin/index.js deleted file mode 100644 index abc456d..0000000 --- a/packages/utils/src/plugin/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export { default as pluginTarget } from './pluginTarget'; -import * as mixins from './mixins'; -export { mixins }; diff --git a/packages/utils/src/plugin/mixins.js b/packages/utils/src/plugin/mixins.js deleted file mode 100644 index 114de2a..0000000 --- a/packages/utils/src/plugin/mixins.js +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Mixes all enumerable properties and methods from a source object to a target object. - * - * @memberof PIXI.utils.mixins - * @function mixin - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function mixin(target, source) -{ - if (!target || !source) return; - // in ES8/ES2017, this would be really easy: - // Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - - // get all the enumerable property keys - const keys = Object.keys(source); - - // loop through properties - for (let i = 0; i < keys.length; ++i) - { - const propertyName = keys[i]; - - // Set the property using the property descriptor - this works for accessors and normal value properties - Object.defineProperty(target, propertyName, Object.getOwnPropertyDescriptor(source, propertyName)); - } -} - -const mixins = []; - -/** - * Queues a mixin to be handled towards the end of the initialization of PIXI, so that deprecation - * can take effect. - * - * @memberof PIXI.utils.mixins - * @function delayMixin - * @private - * @param {object} target The prototype or instance that properties and methods should be added to. - * @param {object} source The source of properties and methods to mix in. - */ -export function delayMixin(target, source) -{ - mixins.push(target, source); -} - -/** - * Handles all mixins queued via delayMixin(). - * - * @memberof PIXI.utils.mixins - * @function performMixins - * @private - */ -export function performMixins() -{ - for (let i = 0; i < mixins.length; i += 2) - { - mixin(mixins[i], mixins[i + 1]); - } - mixins.length = 0; -} diff --git a/packages/utils/src/plugin/pluginTarget.js b/packages/utils/src/plugin/pluginTarget.js deleted file mode 100644 index c4f7a67..0000000 --- a/packages/utils/src/plugin/pluginTarget.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Mixins functionality to make an object have "plugins". - * - * @example - * function MyObject() {} - * - * pluginTarget.mixin(MyObject); - * - * @function pluginTarget - * @memberof PIXI.utils - * @type {mixin} - * @param {object} obj - The object to mix into. - */ -function pluginTarget(obj) -{ - obj.__plugins = {}; - - /** - * Adds a plugin to an object - * - * @param {string} pluginName - The events that should be listed. - * @param {Function} ctor - The constructor function for the plugin. - */ - obj.registerPlugin = function registerPlugin(pluginName, ctor) - { - obj.__plugins[pluginName] = ctor; - }; - - /** - * Instantiates all the plugins of this object - * - */ - obj.prototype.initPlugins = function initPlugins() - { - this.plugins = this.plugins || {}; - - for (const o in obj.__plugins) - { - this.plugins[o] = new (obj.__plugins[o])(this); - } - }; - - /** - * Removes all the plugins of this object - * - */ - obj.prototype.destroyPlugins = function destroyPlugins() - { - for (const o in this.plugins) - { - this.plugins[o].destroy(); - this.plugins[o] = null; - } - - this.plugins = null; - }; -} - -export default { - /** - * Mixes in the properties of the pluginTarget into another object - * - * @param {object} obj - The obj to mix into - */ - mixin: function mixin(obj) - { - pluginTarget(obj); - }, -}; diff --git a/packages/utils/test/index.js b/packages/utils/test/index.js index 52f00ce..bf8041e 100755 --- a/packages/utils/test/index.js +++ b/packages/utils/test/index.js @@ -99,140 +99,6 @@ }); }); - describe('getUrlFileExtension', function () - { - it('should exist', function () - { - expect(utils.getUrlFileExtension) - .to.be.a('function'); - }); - - it('should return extension of URL in lower case', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when absolute', function () - { - const imageType = utils.getUrlFileExtension('/you/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when relative', function () - { - const imageType = utils.getUrlFileExtension('me/baz.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should return extension of URL when just an extension', function () - { - const imageType = utils.getUrlFileExtension('.PNG'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG#derp/this/is/a/path/me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#not-today'); - - expect(imageType) - .to.equal('png'); - }); - - it('should work with a hash path and query string on the url', function () - { - const imageType = utils.getUrlFileExtension('http://foo.bar/baz.PNG?v=1&file=me.jpg#path/s/not-today.svg'); - - expect(imageType) - .to.equal('png'); - }); - }); - - describe('getSvgSize', function () - { - it('should exist', function () - { - expect(utils.getSvgSize) - .to.be.a('function'); - }); - - it('should return a size object with width and height from an SVG string', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return a size object from an SVG string with inverted quotes', function () - { - const svgSize = utils.getSvgSize(""); // eslint-disable-line quotes - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should work with px values', function () - { - const svgSize = utils.getSvgSize(''); - - expect(svgSize) - .to.be.an('object'); - expect(svgSize.width) - .to.equal(64); - expect(svgSize.height) - .to.equal(32); - }); - - it('should return an empty object when width and/or height is missing', function () - { - const svgSize = utils.getSvgSize(''); - - expect(Object.keys(svgSize).length) - .to.equal(0); - }); - }); - describe('sayHello', function () { it('should exist', function () diff --git a/tools/builder/index.js b/tools/builder/index.js deleted file mode 100644 index 49114e0..0000000 --- a/tools/builder/index.js +++ /dev/null @@ -1,115 +0,0 @@ -const path = require('path'); -const buble = require('rollup-plugin-buble'); -const resolve = require('rollup-plugin-node-resolve'); -const string = require('rollup-plugin-string'); -const uglify = require('rollup-plugin-uglify'); -const { minify } = require('uglify-es'); -const minimist = require('minimist'); -const commonjs = require('rollup-plugin-commonjs'); -const builtins = require('rollup-plugin-node-builtins'); -const replace = require('rollup-plugin-replace'); -const preprocess = require('rollup-plugin-preprocess').default; - -const pkg = require(path.resolve('./package')); -const safeName = path.basename(pkg.name); -const input = 'src/index.js'; - -const { prod, format, output } = minimist(process.argv.slice(2), { - string: ['format', 'output'], - boolean: ['prod'], - default: { - format: 'es', - prod: false, - output: '', - }, - alias: { - f: 'format', - p: 'prod', - o: 'output', - }, -}); - -// Allow overriding output, but default to "module" and "main" fields -const file = output || (format === 'es' ? pkg.module : pkg.main); - -const plugins = [ - resolve({ - browser: true, - preferBuiltins: true, - }), - builtins(), - commonjs({ - namedExports: { - 'resource-loader': ['Resource'], - 'pixi-gl-core': ['GLFramebuffer'], - }, - }), - string({ - include: [ - 'src/**/*.frag', - 'src/**/*.vert', - ], - }), - replace({ - __VERSION__: pkg.version, - }), - preprocess({ - context: { - DEV: !prod, - DEVELOPMENT: !prod, - PROD: prod, - PRODUCTION: prod, - }, - }), - buble(), -]; - -if (prod) -{ - let first = true; - - plugins.push(uglify({ - mangle: true, - compress: true, - output: { - comments(node, comment) - { - const { value, type } = comment; - - if (type === 'comment2' && first) - { - first = false; - - return value[0] === '!'; - } - - return false; - }, - }, - }, minify)); -} - -const compiled = (new Date()).toUTCString().replace(/GMT/g, 'UTC'); - -const banner = `/*! - * ${pkg.name} - v${pkg.version} - * Compiled ${compiled} - * - * pixi-filters is licensed under the MIT License. - * http://www.opensource.org/licenses/mit-license - */\n`; - -const name = `__${safeName.replace(/-/g, '_')}`; - -module.exports = { - banner, - name, - input, - output: { - file, - format, - }, - external: Object.keys(pkg.dependencies || []), - sourcemap: true, - plugins, -}; diff --git a/tools/builder/package.json b/tools/builder/package.json index 216f941..f9d1aa9 100644 --- a/tools/builder/package.json +++ b/tools/builder/package.json @@ -2,8 +2,12 @@ "name": "@internal/builder", "version": "5.0.0-alpha", "private": true, - "module": "index.js", - "devDependencies": { + "bin": { + "config": "./rollup.config.js" + }, + "dependencies": { + "buble": "^0.17.0", + "magic-string": "^0.22.4", "minimist": "^1.2.0", "rollup-plugin-buble": "^0.15.0", "rollup-plugin-commonjs": "^8.2.4", @@ -11,6 +15,7 @@ "rollup-plugin-node-resolve": "^3.0.0", "rollup-plugin-preprocess": "0.0.4", "rollup-plugin-replace": "^2.0.0", + "rollup-plugin-sourcemaps": "^0.4.2", "rollup-plugin-string": "^2.0.2", "rollup-plugin-uglify": "^2.0.1", "uglify-es": "^3.0.25" diff --git a/tools/builder/rollup.config.js b/tools/builder/rollup.config.js new file mode 100644 index 0000000..d22c49a --- /dev/null +++ b/tools/builder/rollup.config.js @@ -0,0 +1,130 @@ +import path from 'path'; +import fs from 'fs'; +import buble from 'buble'; +import thaw from './thaw'; +import transpile from 'rollup-plugin-buble'; +import resolve from 'rollup-plugin-node-resolve'; +import string from 'rollup-plugin-string'; +import sourcemaps from 'rollup-plugin-sourcemaps'; +import uglify from 'rollup-plugin-uglify'; +import { minify } from 'uglify-es'; +import minimist from 'minimist'; +import commonjs from 'rollup-plugin-commonjs'; +import builtins from 'rollup-plugin-node-builtins'; +import replace from 'rollup-plugin-replace'; +import preprocess from 'rollup-plugin-preprocess'; + +const pkg = require(path.resolve('./package')); +const input = 'src/index.js'; + +const { prod, bundle, deprecated } = minimist(process.argv.slice(2), { + string: ['deprecated'], + boolean: ['prod', 'bundle'], + default: { + prod: false, + bundle: false, + }, + alias: { + p: 'prod', + b: 'bundle', + r: 'deprecated', + }, +}); + +const plugins = [ + sourcemaps(), + resolve({ + browser: true, + preferBuiltins: true, + }), + builtins(), + commonjs({ + namedExports: { + 'resource-loader': ['Resource'], + 'pixi-gl-core': ['GLFramebuffer'], // TODO: remove pixi-gl-core + }, + }), + string({ + include: [ + 'src/**/*.frag', + 'src/**/*.vert', + ], + }), + replace({ + __VERSION__: pkg.version, + }), + preprocess({ + context: { + DEV: !prod, + DEVELOPMENT: !prod, + PROD: prod, + PRODUCTION: prod, + }, + }), + transpile(), + thaw(), +]; + +if (prod) +{ + plugins.push(uglify({ + mangle: true, + compress: true, + output: { + comments(node, comment) + { + const { value, type } = comment; + + return type === 'comment2' && value.indexOf(pkg.name) > -1; + }, + }, + }, minify)); +} + +let outro = ''; + +if (deprecated) +{ + const buffer = fs.readFileSync(path.resolve(deprecated), 'utf8'); + + outro = buble.transform(buffer).code; +} + +const compiled = (new Date()).toUTCString().replace(/GMT/g, 'UTC'); +const external = Object.keys(pkg.dependencies || []); +const sourcemap = true; +const name = 'PIXI'; +const banner = `/*! + * ${pkg.name} - v${pkg.version} + * Compiled ${compiled} + * + * ${pkg.name} is licensed under the MIT License. + * http://www.opensource.org/licenses/mit-license + */\n`; + +export default [ + { + banner, + outro, + name, + input, + output: { + file: pkg.main, + format: bundle ? 'umd' : 'cjs', + }, + external, + sourcemap, + plugins, + }, + { + banner, + input, + output: { + file: pkg.module, + format: 'es', + }, + external, + sourcemap, + plugins, + }, +]; diff --git a/tools/builder/thaw.js b/tools/builder/thaw.js new file mode 100644 index 0000000..8533b59 --- /dev/null +++ b/tools/builder/thaw.js @@ -0,0 +1,47 @@ +const MagicString = require('magic-string'); + +/** + * This workaround plugin removes `Object.freeze` usage with Rollup + * because there is no way to disable and we need it to + * properly add deprecated methods/classes on namespaces + * such as `PIXI.utils` or `PIXI.loaders`, code was borrowed + * from 'rollup-plugin-replace'. + * @todo Remove this when opt-out option for Rollup is available + * @private + */ +export default function thaw() +{ + const pattern = /Object.freeze\s*\(\s*([^)]*)\)/g; + + return { + name: 'thaw', + transformBundle(code) + { + const str = new MagicString(code); + let hasReplacements = false; + let match; + + while ((match = pattern.exec(code))) + { + hasReplacements = true; + const start = match.index; + + str.overwrite( + start, + start + match[0].length, + match[1] + ); + } + + if (!hasReplacements) + { + return null; + } + + return { + code: str.toString(), + map: str.generateMap({ hires: true }), + }; + }, + }; +}